Cropping to edge
Cropping to edge
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,
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,
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Cropping to edge
Are those the only options in your command? What version IM?
Yes, samples would help: input files that go wrong, and their outputs.
Yes, samples would help: input files that go wrong, and their outputs.
snibgo's IM pages: im.snibgo.com
Re: Cropping to edge
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,
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
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,
Let me find a correct example.
Thanks,
Re: Cropping to edge
Hi,
This is better:
Here is one before:

Then it after:

See how it's off centre.
Thanks,
This is better:
Here is one before:

Then it after:

See how it's off centre.
Thanks,
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Cropping to edge
The background isn't exactly white so you need eg "-fuzz 5%" before the "-trim".
snibgo's IM pages: im.snibgo.com
Re: Cropping to edge
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,
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,
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Cropping to edge
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.
snibgo's IM pages: im.snibgo.com
Re: Cropping to edge
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
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
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,
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,
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Cropping to edge
It isn't touching the edges. You can see a white border.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?
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
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.DomE wrote:Should I have resize and extent set to the same size? Or the resize set to the total canvas size?
snibgo's IM pages: im.snibgo.com
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Cropping to edge
Sorry, my last sentence was wrong. It will be expanded to fit into a box 980x1180.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.
See http://www.imagemagick.org/script/comma ... p#geometry
snibgo's IM pages: im.snibgo.com
Re: Cropping to edge
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,
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,
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Cropping to edge
I don't understand the question. You can see from my code above that "-resize 980x1180" will enlarge an input 892x844 to be 980x927.
snibgo's IM pages: im.snibgo.com
Re: Cropping to edge
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.
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.