Page 1 of 1

Convert portrait and landscape aspect images at the same time

Posted: 2018-06-12T12:19:29-07:00
by RKwasi
I have an image upload form where users submit vertical and horizontal format images.

My problem.
I need the resized images to be these sizes:
(they will usually be these exact sizes actually since they submit files that resize perfectly)

thumb:
80w x 120h
or
120w x 80h

middle:
133w x 200h
200w x 133h

resized:
466w x 700h
or
700w x 466h

I'm using a bootstrap/dropzone.js combo form where they drag and drop the images being uploaded.

My issue is how would I be able to make horizontal aspect images 120, 200 or 700w
and vertical aspect images 80 133 and 466w
and do it all in one command line step (actually, one for each size/folder location etc)

This is my last variation, although everything I've tried including this doesn't achieve the final desired sizes, just horizontal images that are 80 wide instead of 120 w etc.

convert -resize 80x120^ c:\inetpub\wwwroot\kp-new\model_images\[THISFILENAME] -quality 75 c:\inetpub\wwwroot\kp-new\model_images\thumb\[THISFILENAME]
convert -resize 133x200^ c:\inetpub\wwwroot\kp-new\model_images\[THISFILENAME] -quality 75 c:\inetpub\wwwroot\kp-new\model_images\middle\[THISFILENAME]
convert -resize 466x700^ c:\inetpub\wwwroot\kp-new\model_images\[THISFILENAME] -quality 75 c:\inetpub\wwwroot\kp-new\model_images\resize\[THISFILENAME]

Is what I'm trying to do even possible?
Can I read into an image and determine if its a vertical or horizontal?

I am doing this on a windows server.

Re: Convert portrait and landscape aspect images at the same time

Posted: 2018-06-12T13:02:47-07:00
by fmw42
I am not sure I understand. If you resize image, if the aspect ratio changes, you cannot get both the width and height to stay the same. So you would have to crop or pad depending upon how you resize. But if you want one command to resize using your values, then you need to use parenthesis processing and clones.

Code: Select all

convert image.jpg -quality 75 ^
( -clone 0 -resize 80x120^ -gravity center -extent 80x20 +write thumb1.jpg ) ^
( -clone 0 -resize 133x200^ -gravity center -extent 133x200 +write thumb2.jpg ) ^
( -clone 0 -resize 466x700^ -gravity center -extent 466x700 +write thumb3.jpg ) ^
null:
If you do not want or need the cropping from the -extent, then remove -gravity center -extent WxH.


See
http://www.imagemagick.org/Usage/basics/#parenthesis
http://www.imagemagick.org/Usage/basics/#clone
http://www.imagemagick.org/Usage/files/#write

Please always provide your ImageMagick version and platform/OS (which I assume is Windows from your folder syntax)

Re: Convert portrait and landscape aspect images at the same time

Posted: 2018-06-12T13:24:50-07:00
by RKwasi
If someone uploaded a vertical aspect image, I need it to be 466w x 700h max
If someone uploaded a horizontal aspect image, I need it to be 700w x 466h max

They would in all likelihood do a combination of horizontal and vertical aspect images at the same time in the same upload form.

As an example when someone uploads a vertical image it resizes to 80w x120h in the thumbnail folder.
BUT
when they upload a horizontal image it resizes to 80w x53h in the thumbnail folder.
I need the horizontal images to be resized to 120w x 80h

Same for the other 2 sizes.
The horizontal images get sized to a different width, not the same width as the vertical images.

Does that make sense?

Re: Convert portrait and landscape aspect images at the same time

Posted: 2018-06-12T13:26:35-07:00
by RKwasi
On my Windows 2012 R2 Server I'm using
ImageMagick-7.0.1-Q8

on my desktop I'm still using
ImageMagick-6.9.3-Q8

I should probably upgrade the vers on my PC to be in sync with my server

Re: Convert portrait and landscape aspect images at the same time

Posted: 2018-06-12T13:47:55-07:00
by RKwasi
Found a post here on the forum that pointed me in the right direction.

Doing this:
convert -resize "120x120>" c:\inetpub\wwwroot\kp-new\model_images\[THISFILENAME] -quality 75 c:\inetpub\wwwroot\kp-new\model_images\thumb\[THISFILENAME]
convert -resize "200x200>" c:\inetpub\wwwroot\kp-new\model_images\[THISFILENAME] -quality 75 c:\inetpub\wwwroot\kp-new\model_images\middle\[THISFILENAME]
convert -resize "700x700>" c:\inetpub\wwwroot\kp-new\model_images\[THISFILENAME] -quality 75 c:\inetpub\wwwroot\kp-new\model_images\resize\[THISFILENAME]


.....works perfectly.

Re: Convert portrait and landscape aspect images at the same time

Posted: 2018-06-12T14:24:32-07:00
by Bonzo
Your input image name/path should come before the -resize

Re: Convert portrait and landscape aspect images at the same time

Posted: 2018-06-12T14:43:57-07:00
by fmw42
Well then try

Code: Select all

convert image.jpg -quality 75 ^
( +clone -resize 700x700^ +write thumb1.jpg ) ^
( +clone -resize 200x200^ +write thumb2.jpg ) ^
( +clone -resize 120x120^ +write thumb3.jpg ) ^
null:
On IM 7 replace convert with magick.