我有Ubuntu 10.04。我通过终端使用以下命令转换了图像:
但是我想调整转换后图像的高度和宽度。有没有办法做到这一点?
convert myfigure.png myfigure.jpg
但是我想调整转换后图像的高度和宽度。有没有办法做到这一点?
convert myfigure.png myfigure.jpg
同样的命令,加上一个额外的选项:
convert myfigure.png -resize 200x100 myfigure.jpg
或者
convert -resize 50% myfigure.png myfigure.jpg
find . -maxdepth 1 -iname "*.jpg" | xargs -L1 -I{} convert -resize 30% "{}" _resized/"{}"
sudo apt-get install imagemagick
mogrify -resize 320x240 Image.png
mogrify -resize 50% Image.png
mogrify -resize 320x240 *.jpg
nautilus-image-converter
sudo apt-get install nautilus-image-converter
由於Ubuntu內建了Python,您也可以使用Python腳本來實現這一點,並對所發生的情況有更多控制 - 可以參考這個stackoverflow問題中的示例腳本。這些示例僅使用標準庫。
腳本#1
import os, sys
import Image
size = 128, 128
for infile in sys.argv[1:]:
outfile = os.path.splitext(infile)[0] + ".thumbnail"
if infile != outfile:
try:
im = Image.open(infile)
im.thumbnail(size, Image.ANTIALIAS)
im.save(outfile, "JPEG")
except IOError:
print "cannot create thumbnail for '%s'" % infile
from PIL import Image
import sys
filename = sys.argv[1:]
basewidth = 300
img = Image.open(filename)
wpercent = (basewidth/float(img.size[0]))
hsize = int((float(img.size[1])*float(wpercent)))
img = img.resize((basewidth,hsize), Image.ANTIALIAS)
img.save(filename)
现在,如何通过终端完成这个操作...
sudo nano resizescript.py
python resizescript.py yourfilenamehere.jpg
使用脚本#2:
python resizescript.py yourfilenamehere.jpg
python3-pil
的包名存在。除此之外,你还可以通过pip3
软件包管理器来获取。 - Sergiy Kolodyazhnyy
convert -resize 50% myfigure.png myfigure.jpg
。 - Januaryconvert -resize 50% *.JPG
这个命令可以吗?谢谢。 - Ehsan M. Kermanifind -maxdepth 1 . -iname "*.jpg" | xargs -l -i convert -resize 50% {} /tmp/{}
来源:https://www.perturb.org/display/632_ImageMagick_resize_images.html 我添加了maxdepth
:) - test30×
是 ASCII 字符0xD7
(乘号);代码需要将其替换为实际的x
才能正常运行。请参考 StackOverflow: Invalid argument for option '-resize' in shell script。 - IQAndreassudo apt install imagemagick
安装convert
。 - user677955for f in *.jpg; do echo "正在处理文件 $f.."; convert -resize 25% $f small$f; done
- Palohafind . -maxdepth 1 -iname "*.png" | xargs -L1 -I{} convert "{}" -resize 30% ./small/"{}"
。 - Alex