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.
Can anyone help me please?
fit multiple images on background image
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: fit multiple images on background image
If you converted jpgs are not the same aspect ratio as the background area, then it must be cropped or padded or stretched.
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
windows syntax
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
Code: Select all
convert -density XX image.pdf image.jpg
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
Code: Select all
convert backgroundimage ( image-N.jpg -extent WxH ) -geometry +X+Y -compose over -composite result-N.jpg
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
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?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: fit multiple images on background image
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.
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
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
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
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
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
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: fit multiple images on background image
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.