Page 1 of 1

Batch Resize and Auto Fill/Blend in Boarder

Posted: 2012-06-28T00:08:52-07:00
by bluegti02
I just want to applogize but I am low on time and have not had a chance to heavily investigate to see if this has been already asked/solved. I've started to read some of the documentation but not 100% sure if I understand it or if it is what I am looking for.

Long story short, I have over 500 images that unfortinately are 4320 x 3240. I am using them in a website and they need to be 1:1 (perfect square). All images are just pictures of eyewear with a plain background and placed close to the bottom and are fitted on the left and right so you cannot crop out the left and right sides to make it square. I've inlucded a sample picture bloew.

Image

I've been using GIMP going one by one but not only does it take forever, some of them look sloppy. I was extending the canvas to be 4320 x 4320, therefore adding white space under the image. I then selected a thin strip at the bottom of the image from the left edge to the right edge (full horizontal width) and then scaling it down over the white space. This method is a pain and then two doesn't always work. There are picutes in which the shadows from the eyewear go to the bottom of the image and then I am forced to include them in the thin strip which gets scaled over the white space and that streched shadow doesn't look too good. Here is an example of what I mean when the shadow gets scaled/streched out.

Image

Is there a way in which I can square out an image and make the height and width 1:1 without having a white block? Most images the bottom of the pic can be used to fill in the new space after being squared but its a lot to do manyally. I am open to other suggestions as well so It doesn't have to do this way, but the only requirement is that the images become square.

I am also trying to figure out how to convert multiple images in one shot. I found a command lin syntax that adds white space under the photo making it 1:1 but not sure how to do all 500+ photos in one command line.

Re: Batch Resize and Auto Fill/Blend in Boarder

Posted: 2012-06-28T09:39:05-07:00
by fmw42
Your pictures do not show.

IM can easily convert your images to square, by either padding or cropping or distorting them. The IM mogrify command can work on a whole folder of images. But if each image is a different size, then other size arguments need to be determined, that cannot be done in mogrify. Thus you might need to write a script loop to process each image in your directory separately. Until we see your examples and have further information about your image sizes, we cannot help much other than to point you to the following:

http://www.imagemagick.org/Usage/crop/#crop
http://www.imagemagick.org/Usage/crop/#extent
http://www.imagemagick.org/Usage/basics/#mogrify
http://www.imagemagick.org/Usage/thumbnails/#pad
http://www.imagemagick.org/Usage/thumbnails/#cut

Re: Batch Resize and Auto Fill/Blend in Boarder

Posted: 2012-06-28T13:25:47-07:00
by bluegti02
You should be able to see them now. All my images are the same size, 4320 x 3240. I reduced them for this forum so they would fix. I need to make them 4320 x 4320 without any white space. In other words I want to make them look like they were originally taken 1:1.

Re: Batch Resize and Auto Fill/Blend in Boarder

Posted: 2012-06-28T13:46:40-07:00
by fmw42
bluegti02 wrote:You should be able to see them now. All my images are the same size, 4320 x 3240. I reduced them for this forum so they would fix. I need to make them 4320 x 4320 without any white space. In other words I want to make them look like they were originally taken 1:1.
you only have a few choices: 1) distort them to be square or 2) crop them say in the center to be square, 3) pad them to be square, 4) extend the edges to fill the square

Using your example image, which is 562 × 422

Try these variations.


convert GRATIA_COL02.jpg -resize 562x562\! GRATIA_COL02_562d.jpg

convert GRATIA_COL02.jpg -gravity center -crop 422x422+0+0 +repage GRATIA_COL02_422c.jpg

convert GRATIA_COL02.jpg -resize 562x562 -background white -gravity center -extent 562x562 GRATIA_COL02_562ex.jpg

convert GRATIA_COL02.jpg -define distort:viewport=562x562+0-70 -virtual-pixel edge -distort SRT 0 +repage GRATIA_COL02_562ed.jpg


If on command line windows (not PHP), you may need to use ^ to escape the ! rather than \ or just enclose the 562x562! in double quotes.

see
http://www.imagemagick.org/Usage/windows/

Also for some of the above you may need a relatively current version of IM. You did not mention what version you are using.

Re: Batch Resize and Auto Fill/Blend in Boarder

Posted: 2012-06-28T18:46:45-07:00
by anthony
This would be an example of 'hole filling'. Where the 'hole' in this case is surrounding the main image.

Essentially you want to expand the edge in a useful ay.

One example of hole filling (similar to what you are after) is using shepards sparse color....
http://www.imagemagick.org/Usage/canvas/#sparse_fill

And in a script
http://www.imagemagick.org/Usage/script ... l_shepards

Another is text and logo removal (using blur)
http://www.imagemagick.org/Usage/photos/#removing

Other methods have also been discussed on the forum...
Typically involving text removal from an image of a duck.
viewtopic.php?f=1&t=12517

Re: Batch Resize and Auto Fill/Blend in Boarder

Posted: 2012-06-29T09:08:46-07:00
by bluegti02
Thank you both for replying very promptly, thoroughly and not assuming I understand certain things. So far, I like

convert GRATIA_COL02.jpg -define distort:viewport=562x562+0-70 -virtual-pixel edge -distort SRT 0 +repage GRATIA_COL02_562ed.jpg

except we have a zoom on the image and when you zoom it becomes very obvious. The second command line, just actually crops out the picture so I get just a tiny part of the frame. I haven't gotten a chance to read into Antony's methods but I will this weekend.

So far, I like the one convert method I listed above and would like to use that until I find a better method. Can I run this command on all 400 of my images without having to do one by one by one?

Thanks!

Re: Batch Resize and Auto Fill/Blend in Boarder

Posted: 2012-06-29T12:17:47-07:00
by fmw42
see mogrify

http://www.imagemagick.org/Usage/basics/#mogrify

But recommend you send the output to a different directory so as not to write over the originals

You may need to create the new directory ahead of time


cd to directory where you have input images
mogrify -path "path2newdirectory" -format jpg -define distort:viewport=562x562+0-70 -virtual-pixel edge -distort SRT 0 +repage *.jpg


The only possible issue is that mogrify is old and may not know about the -define or -distort. I have not tried it, so it may work.

Be sure to change your viewport to the max dimension of your actual images and the proper offset to get it centered. Offset=(width-height)/2 assuming the width is larger than the height. Then put that value above replacing the 70 but keep the minus sign.