Resizing and using xc: white to fill empty space not working

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Post by Bonzo »

Code: Select all

convert -size 100x100 old.jpg -thumbnail '60x60>' -gravity center -crop 80x60+0+0\! -background white -flatten new.jpg
This came from the examples site, try it and you should be able to modify it to suit your needs.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Post by Bonzo »

I do not quite understand what you are after Medianeer.

This code will create a thumbnail out of any size image and then add the white border around it so it is 80x60.

Are you saying your original images are 400 x 300 ?

In any case just give the code a go and try modifying it to get the results you want.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

-thumbnail will for for any sized image. it is equivelent to -resize and -strip with a small amount of extra code to handle very very large images (for speed). you should have no trouble if you are looking to create 400x300 'thumbnails' ;-) just adjust the arguments as appropriate.

If your images are smaller then the argument size the '>' ensures they do not enlarge,
and the -crop -flatten will still pad out the image as approparite.

the -size part is to speed up reading of JPEG images. Turn off if you plan to read in or create other images. Reading non-JPEg images ignores that setting.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Post by Bonzo »

Medianeer

I have tried your code and mine; they all do something but mine give a background padding and yours do not !

It may be something to do with the way your server is setup I suppose or the ImageMagick version.

Here is a link to my tests http://www.rubblewebs.co.uk/imagemagick ... r/test.php I have included the original image and rotated it through 90% to see the effect better on the first tests.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

Note -size only effects image creation and JPG reading. It does not effect anything else.
It should probbaly be set to at least double the final size so IM can resize the image properly.

Also the -dither option is the default, it is NOT needed, and may infact change to allow the addition of a 'error correction dither type', in a future IM. +dither is fine to turn off dithering.

I also recommend you read in the image BEFORE using a operator like -resize, -crop and -flatten. Other wise you are using a legacy mode in which order of operation is NOT guranteed.
EG: you may be -flattening your image before you -resize or -crop your image!!!!
This is probably the source of your problem.

See IM Examples Basics -- Legacy mode...
http://www.cit.gu.edu.au/~anthony/graph ... cs/#legacy

It is only present for backward compatibility, and probably should start producing warnings about IM being used in a 'legacy' syle. Avoid it!!!!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply