Page 1 of 1

fit multiple images on background image

Posted: 2015-10-17T23:56:02-07:00
by ikhlief
Hi, I am new here and I was wondering if I can do the following with image magic:

1. I have pdf with multiple pages, I want to convert them into JPG.
2. I have a background image with fixed width and height which will work as a container.
3. I want to place each of the converted JPGs alone on the background image and fit it on the background image with stretching and keeping the image proportion, so the background image will fill the empty space around it.
4. I want to save the result image as JPG in two different specific sizes.

Image


Image


Can anyone help me please?

Re: fit multiple images on background image

Posted: 2015-10-18T00:17:30-07:00
by fmw42
If you converted jpgs are not the same aspect ratio as the background area, then it must be cropped or padded or stretched.

Code: Select all

convert -density XX image.pdf image.jpg
will convert each page to image-N.jpg where N = 0, 1, 2 ... number of pages you have. The density needs to be adjusted to ensure that the pdf page has a size near the space you want to fill. You will then need to crop or pad (-extent) and composite it over your background in the right place.

unix syntax

Code: Select all

convert backgroundimage \( image-N.jpg -background somecolor -gravity center -extent WxH \) -geometry +X+Y -compose over -composite result-N.jpg
windows syntax

Code: Select all

convert backgroundimage ( image-N.jpg -extent WxH ) -geometry +X+Y -compose over -composite result-N.jpg
See

http://www.imagemagick.org/script/comma ... php#extent
http://www.imagemagick.org/Usage/thumbnails/#pad
http://www.imagemagick.org/Usage/thumbnails/#cut
http://www.imagemagick.org/Usage/basics/#parenthesis
http://www.imagemagick.org/Usage/compose/#compose
http://www.imagemagick.org/Usage/layers/#convert

Re: fit multiple images on background image

Posted: 2015-10-18T00:25:46-07:00
by ikhlief
If the converted images are 2000*700px , and the background image I need is 2000*900px, what I want that the converted image will fit on the background so the width will fill but the height will have 200px more so this will appear from the background image, but it should be 100px above the picture and 100px below the picture, can I do this?

Re: fit multiple images on background image

Posted: 2015-10-18T00:43:41-07:00
by fmw42
Sorry, I am not sure I understand. If your converted image is 200 px smaller in height than the area you want to fill, then it needs to be padded or some of your background will show. If you leave it at 2000x700, you can use -gravity center before the -compose, if your region of the background is centered

The first thing you need to do is to get the right density so that your resulting images will be 2000xH, where we do not know yet the height. So convert the first page to jpg and see what size it comes out.

Code: Select all

convert image.pdf[0] image-0.jpg
then you can compute the needed density as density=72*2000/width, where 72 is nominal dpi and width is the width of the resulting jpg.

Or you can use a large density and resize down to 2000, such as

Code: Select all

convert -density 300 image.pdf -resize 2000x2000 image.jpg
This will make either the width or height of the result 2000 depending upon the pdf aspect ratio and the other dimension will be smaller in proportion. The disadvantage is that it will be slower, but the result will be higher quality.

Once you have the right size, you can just composite it in the center of the background

Code: Select all

convert backgroundimage image-N.jpg -gravity center -compose over -composite result-N.jpg

Re: fit multiple images on background image

Posted: 2015-10-18T00:53:08-07:00
by fmw42
If you post your background image and your pdf, we can show you how to do this. You will need to post your image to some place such as dropbox.com and put the URLs here. There is no image upload directly to this web site.