Suppose I have a image named 1.png
which is currently
500px : height
1000px : width
I want to resize it to:
50px : height
100px : width
It must be output in PNG format, not JPG. An example would be highly appreciated.
Suppose I have a image named 1.png
which is currently
500px : height
1000px : width
I want to resize it to:
50px : height
100px : width
It must be output in PNG format, not JPG. An example would be highly appreciated.
I'd use convert
or mogrify
from the ImageMagick suite.
$ convert -resize 100x50 1.png 2.png
# or #
$ mogrify -resize 100x50 1.png
convert
takes a separate output filename; creating a separate file.
mogrify
doesn't take a separate output filename; modifying the file in place
convert -resize 50%x50% 1.png 2.png
, or just convert -resize 50% 1.png 2.png
.
– choroba
Mar 30 '20 at 15:07
The answers you have gotten so far will work in this particular case because your source and target images have the same aspect ratio. However, if you want to change to an arbitrary size, they will fail:
$ file foo.png
foo.png: PNG image data, 1000 x 500, 8-bit/color RGB, non-interlaced
$ convert -resize 100x50 foo.png bar.png
$ file bar.png
bar.png: PNG image data, 100 x 50, 8-bit colormap, non-interlaced
As you can see above, the simple convert works fine when not changing the image's proportions. But what if you want to change them?
$ convert -resize 200x50 foo.png bar.png
$ file bar.png
bar.png: PNG image data, 100 x 50, 8-bit colormap, non-interlaced
So, when changing the proportions, the command above fails. In order to force convert
to change an image this way, you need to add a !
to the end of the geometry specification (and, since !
is a special character to many shells, you need to escape it as \!
):
$ convert -resize 200x50\! foo.png bar.png
$ file bar.png
bar.png: PNG image data, 200 x 50, 8-bit colormap, non-interlaced
Use Imagemagick for this.
Read the man page for correct use but it should work by passing parameters, something like
convert 1.png -resize 50x100 1-resized.png
An alternative to ImageMagick is the venerable netpbm:
pngtopnm input.png | pnmscale -reduce 10 | pnmtopng > output.png
pngtopnm
really well known/respected? This is the first I've heard of it.
– voices
Feb 24 '16 at 04:01
apt-cache search thumbnailer
on a Debian-based system for instance). – Stéphane Chazelas Jun 26 '14 at 12:30