Page 1 of 1
Can someone explain the -sample option to me?
Posted: 2019-04-22T08:42:27-07:00
by rtkohl
I am brand new to Imagemagick and I am having a hard time understanding what the -sample command does.
First I am using ImageMagick 6.9.2-6 not sure if that matters but wanted to share that info.
what would the result be if I run this command:
Imconvert.exe 1.jpg -sample 1024x768 2.jpg
Currently 1.jpg is 500x499
should that make 2.jpg a 1024x768 version of 1.jpg?
It currently makes it a 770x768 version of 1.jpg which was confusing me but as i am typing this I am wondering if it is keeping the aspect ration of the original image which is why it did not make it 1024x768. Is that correct?
If that is correct, is there a command I can use to take the original image and make it 1024x768 or would that just distort the image?
Re: Can someone explain the -sample option to me?
Posted: 2019-04-22T10:21:28-07:00
by fmw42
ImageMagick -sample, -scale and -resize will enlarge but keep the aspect ratio. Your input is nearly square but you are asking for a non square output. So you will get an output that is nearly square and the size of the smaller dimension. If you want it larger, then use ^ symbol.
convert -size 500x499 xc:red red.jpg
convert red.jpg -sample 1024x768 red2.jpg
770x768
You can then pad it to your desired size using -extent.
convert red.jpg -sample 1024x768^ red3.jpg
1024x1022
You can then crop it to your desired size with -crop
If you want to distort it so that it is exactly your desired size, then use the ! symbol
See
https://imagemagick.org/script/command- ... p#geometry
I would also point out that -sample and -scale will enlarge using pixel replication. This will produce a blocky output. If you use -resize, it will interpolate. The result will be smoother.
____________________
Please, always provide your IM version and platform when asking questions, since syntax may differ.
Also provide your exact command line and your images, if possible.
See the top-most post in this forum "IMPORTANT: Please Read This FIRST Before Posting" at
http://www.imagemagick.org/discourse-se ... f=1&t=9620
If using Imagemagick 7, then see
http://imagemagick.org/script/porting.php#cli
For novices, see
http://www.imagemagick.org/discourse-se ... f=1&t=9620
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
https://github.com/ImageMagick/usage-markdown
https://imagemagick.org/script/porting.php#cli
Re: Can someone explain the -sample option to me?
Posted: 2019-04-23T10:03:29-07:00
by rtkohl
Thanks for clarifying!
Is there someplace I could have read that? when I look at the command line options page, I can find the -sample command however I see no reference to the ^ and ! qualifiers you are talking about and I would like to know what they mean.
Thanks again for the quick reply.
Rich
Re: Can someone explain the -sample option to me?
Posted: 2019-04-23T10:09:55-07:00
by rtkohl
Nevermind, I found it in your for novices section.
Thanks
Re: Can someone explain the -sample option to me?
Posted: 2019-04-23T11:14:53-07:00
by fmw42
Yes, the docs for -sample have a link to Image Geometry (
https://imagemagick.org/script/command- ... p#geometry) which is the link I posted above. It explains about the ^ and other symbols for specifying the desired size.