Page 1 of 1

resize, crop and watermark

Posted: 2014-03-05T09:38:16-07:00
by jasonm
Hi,

I'm new to ImageMagick and little confused how to do the following to a batch of images in a folder.

1. the images in the folder are various widths and heights (eg. 900x1759, 1280x400, etc)
2. re-size the images to 200px at the shortest dimension (either width or height)
3. crop the images in the center of the re-sized images (eg. 900x1759 => re-size to 200x391 => crop centered 200x200)
4. small transparent "text" watermark in the bottom left hand corner (eg. www)

Thank you for your help!

Re: resize, crop and watermark

Posted: 2014-03-05T09:48:33-07:00
by snibgo
2. I think "-resize 200x200^" is what you want. See http://www.imagemagick.org/script/comma ... p#geometry

3. "-gravity center -crop 200x200+0+0"

4. Lots of ways, including:

-gravity SouthWest -fill rgba(100%,0,0,0.75) -annotate 0 "www.something"

Re: resize, crop and watermark

Posted: 2014-03-05T10:02:25-07:00
by jasonm
I tried -resize 200x200 but it does not seem to pick the shortest side - I end up with something like 156x200.
convert 1fc214004c9481e4c8073e85323bfd4b.png -resize 200x200 -gravity center -crop 200x200+0+0 200x200.png

I tried the following:
convert 1fc214004c9481e4c8073e85323bfd4b.png -trim -resize 200x200 -gravity center -extent 200x200 200x200.png
but the resulting image is not proportional.

Thank you.

Re: resize, crop and watermark

Posted: 2014-03-05T10:07:09-07:00
by snibgo
-resize 200x200^
with a caret ^

Re: resize, crop and watermark

Posted: 2014-03-05T10:14:58-07:00
by jasonm
Thanks! I missed the caret ^ ... Is it possible to make two different but proportional thumbnails out of this resized and crop image at the same time?

eg. 900x1759 => 200x200 (resized, cropped) => 100x100 thumbnail => 50x50 thumbnail

Thank you.

Re: resize, crop and watermark

Posted: 2014-03-05T10:24:12-07:00
by snibgo
Yes. "-write" will write all of the images in the current list. You could for example:

Code: Select all

convert in.png
  ( +clone -resize 200x200^ -crop 200x200+0+0 -write out1.png +delete )
  ( +clone -resize 100x100^ -crop 100x100+0+0 -write out2.png +delete )
  etc...
  NULL:

Re: resize, crop and watermark

Posted: 2014-03-05T10:40:50-07:00
by jasonm
I added the -gravity center command and it works! However, I'm getting duplicates;

[ ] +delete-0 05-Mar-2014 12:34 12K ????
[ ] +delete-1 05-Mar-2014 12:34 12K ????
[IMG] 1fc214004c9481e4c8073e85323bfd4b.png 20-Feb-2012 19:41 492K
[IMG] out1-0.png 05-Mar-2014 12:34 54K
[IMG] out1-1.png 05-Mar-2014 12:34 54K
[IMG] out2-0.png 05-Mar-2014 12:34 12K
[IMG] out2-1.png

convert 1fc214004c9481e4c8073e85323bfd4b.png +clone -resize 200x200^ -gravity center -crop 200x200+0+0 -write out1.png +delete +clone -resize 100x100^ -gravity center -crop 100x100+0+0 -write out2.png +delete

Thank you.

Re: resize, crop and watermark

Posted: 2014-03-05T10:45:58-07:00
by snibgo
Parentheses ( ) and final NULL:

Re: resize, crop and watermark

Posted: 2014-03-05T11:05:30-07:00
by jasonm
I removed the () because I was getting this error;

convert 1fc214004c9481e4c8073e85323bfd4b.png (+clone -resize 200x200^ -gravity center -crop 200x200+0+0 -write out1.png +delete) (+clone -resize 100x100^ -gravity center -crop 100x100+0+0 -write out2.png +delete) NULL:
-bash: syntax error near unexpected token `('

Thank you.

Re: resize, crop and watermark

Posted: 2014-03-05T11:08:49-07:00
by fmw42
Parentheses must have spaces before and after on each one.

Code: Select all

convert 1fc214004c9481e4c8073e85323bfd4b.png ( +clone -resize 200x200^ -gravity center -crop 200x200+0+0 -write out1.png +delete ) ( +clone -resize 100x100^ -gravity center -crop 100x100+0+0 -write out2.png +delete ) NULL:

Re: resize, crop and watermark

Posted: 2014-03-05T11:15:32-07:00
by jasonm
I tried both, even copied and pasted in the Code: Select all ... still error -bash: syntax error near unexpected token `('

Re: resize, crop and watermark

Posted: 2014-03-05T11:32:54-07:00
by snibgo
I don't do Unix but I think you need to escape the parentheses: \( and \)

Re: resize, crop and watermark

Posted: 2014-03-05T11:39:58-07:00
by jasonm
good one! I'm no unix guru but escape the parentheses worked!

Thank you!

Re: resize, crop and watermark

Posted: 2014-03-05T12:24:29-07:00
by fmw42
It is always a good idea to identify your IM version and platform when asking a question on this forum. That skips wasted time about syntax differences between Unix and Windows.

Please review viewtopic.php?f=1&t=9620 which is the very first post (and permanently first post) at the top of the Users forum.