Page 1 of 2
Cropping to edge
Posted: 2014-02-05T05:46:48-07:00
by DomE
Hi,
I'm always trying to crop an image to be 1000x1200 regardless of the size, be it smaller or larger. If it's larger put it on a white background. The image needs to be centred / in the middle.
I'm currently using:
-trim +repage -resize 980x1180 -gravity center -extent 980x1180 -bordercolor White -border 10x10
Which mostly works, however I'm getting quite a few images where it's not cropping the image to the edge and it's ending up in the centre with a large white space round the edge.
The border is there so the image doesn't touch the edge exactly.
Also every now and again the image won't be in the middle of the of the page.
I can provided examples if needed.
Thanks,
Re: Cropping to edge
Posted: 2014-02-05T06:03:24-07:00
by snibgo
Are those the only options in your command? What version IM?
Yes, samples would help: input files that go wrong, and their outputs.
Re: Cropping to edge
Posted: 2014-02-05T06:24:26-07:00
by DomE
Hi,
Yes they're the only options in my command. I'm using version - ImageMagick-6.8.8-2
This is before:
This is after:
You can see a white outline on the image on the after photo towards the border also, so I suspect that is something to do with it.
Thanks,
Re: Cropping to edge
Posted: 2014-02-05T06:50:15-07:00
by DomE
In fact, ignore that example, it's correct, the image isn't big enough, so that's right.
Let me find a correct example.
Thanks,
Re: Cropping to edge
Posted: 2014-02-05T06:54:13-07:00
by DomE
Hi,
This is better:
Here is one before:
Then it after:
See how it's off centre.
Thanks,
Re: Cropping to edge
Posted: 2014-02-05T07:15:22-07:00
by snibgo
The background isn't exactly white so you need eg "-fuzz 5%" before the "-trim".
Re: Cropping to edge
Posted: 2014-02-05T07:26:22-07:00
by DomE
Thanks for that, seems to have worked.
Can I clarify, as my images are say 800x900 and it's putting them onto a 1000x1200 canvas, is it actually re-sizing the image to fit it on. i.e. isn't just putting the 800x900 onto a 1000x1200 canvas, but actually re-sizing the 800x900 to that size?
Thanks,
Re: Cropping to edge
Posted: 2014-02-05T07:32:00-07:00
by snibgo
You have "-resize 980x1180". If the input is wider than 980 or taller than 1180 it will be shrunk. If the input is 800x900 it won't change size.
Re: Cropping to edge
Posted: 2014-02-05T07:38:44-07:00
by DomE
Hi,
I'm not complaining, because it's working well, just double checking how it is working.
For example this image starts off at 892x844:
But when I've run it through, it comes out at 1000x1200 and the image is touching the edges, so it's expanded it to fit?
Thanks
Re: Cropping to edge
Posted: 2014-02-05T07:52:16-07:00
by DomE
Sorry for all the questions..
Should I have resize and extent set to the same size? Or the resize set to the total canvas size?
-resize 1000x1200 -gravity center -extent 980x1180
or
-resize 980x1180 -gravity center -extent 980x1180
Either work, just want to be sure I'm using the correct one.
Thanks,
Re: Cropping to edge
Posted: 2014-02-05T08:31:14-07:00
by snibgo
DomE wrote:But when I've run it through, it comes out at 1000x1200 and the image is touching the edges, so it's expanded it to fit?
It isn't touching the edges. You can see a white border.
You can see what happens at each stage:
Code: Select all
F:\web\im>%IM%identify 2vi5uo7.jpg
2vi5uo7.jpg JPEG 892x844 892x844+0+0 8-bit sRGB 97.9KB 0.000u 0:00.000
F:\web\im>%IM%identify 2cosoeq.jpg
2cosoeq.jpg JPEG 1000x1200 1000x1200+0+0 8-bit sRGB 185KB 0.000u 0:00.000
F:\web\im>%IM%convert 2vi5uo7.jpg -fuzz 5% -trim info:
2vi5uo7.jpg JPEG 892x844 892x844+0+0 8-bit sRGB 0.141u 0:00.281
F:\web\im>%IM%convert 2vi5uo7.jpg -fuzz 5% -trim -resize 980x1180 info:
2vi5uo7.jpg JPEG 980x927 980x927+0+0 8-bit sRGB 0.125u 0:00.016
F:\web\im>%IM%convert 2vi5uo7.jpg -fuzz 5% -trim -resize 980x1180 -extent 980x1180 info:
2vi5uo7.jpg JPEG 980x1180 980x1180+0+0 8-bit sRGB 0.141u 0:00.038
F:\web\im>%IM%convert 2vi5uo7.jpg -fuzz 5% -trim -resize 980x1180 -extent 980x1180 -bordercolor white -border 10x10 info:
2vi5uo7.jpg JPEG 1000x1200 1000x1200+0+0 8-bit sRGB 0.000u 0:00.000
DomE wrote:Should I have resize and extent set to the same size? Or the resize set to the total canvas size?
It depends on what you want. If you "-resize 1000x1200" then larger photos will be shrunk to fit in a box that size, and then the border will be added, so the final image could be 1120x1220.
Re: Cropping to edge
Posted: 2014-02-05T09:40:17-07:00
by snibgo
snibgo wrote:You have "-resize 980x1180". If the input is wider than 980 or taller than 1180 it will be shrunk. If the input is 800x900 it won't change size.
Sorry, my last sentence was wrong. It will be expanded to fit into a box 980x1180.
See
http://www.imagemagick.org/script/comma ... p#geometry
Re: Cropping to edge
Posted: 2014-02-05T09:42:03-07:00
by DomE
Hi,
Sorry that's not what I was meaning.
The image is starting at 892x844 and finishing at 1000x12000 and on the 1000x1200 even with the border is bigger than the 892x844 - so we're taking that smaller 892x844 and making it larger aren't we?
It's adding about 100px to each side etc.
So it's expanding my original image to fit the canvas?
Thanks,
Re: Cropping to edge
Posted: 2014-02-05T10:41:16-07:00
by snibgo
I don't understand the question. You can see from my code above that "-resize 980x1180" will enlarge an input 892x844 to be 980x927.
Re: Cropping to edge
Posted: 2014-02-05T10:48:04-07:00
by DomE
snibgo wrote:
You have "-resize 980x1180". If the input is wider than 980 or taller than 1180 it will be shrunk. If the input is 800x900 it won't change size.
It was this bit that confused me because you said 800x900 it won't change the input size, but it looks like it making the original image larger.