Page 3 of 3

Re: Fit one image on its place on another image

Posted: 2010-06-06T04:43:28-07:00
by Fludimir
Thanks for help, both your methods works fine. But now I have some another problem :)
I have an image with alpha. Exacty I've created it from base image and mask:

Code: Select all

convert user_photo_resized.tga  -auto-level -brightness-contrast 0,4 -color-matrix ".788 0 0 0 .98 0 0 0 .996" \
 mask_all.jpg user_photo_current_part.tga
One strange thing - I cant see alpha on the result image in any program, but ImageMagick uses it right

And I have to compose this image with alpha, background image, and use second mask when composing with background. Here is command which I tried to use:

Code: Select all

convert "f0022.jpg" \( user_photo_current_part.tga -virtual-pixel transparent -background none -gravity northwest \
-extent 768x432 -distort Perspective "0,0 549,22  300,0 604,122  300,400 439,194  0,400 397,97" \) \
mask_20_25.jpg -composite result.jpg
But.. mask_20_25.jpg did not works, result image composed without it. I tried to use +distort - this works well with mask, but foreground image placed in the top left corner of background, instead of right place

[url=http://bu.fullrest.ru/pack.rar]Here[url] is archive with all base images and result

It will be perfect if commandline for composing will not be greatly different from mine, and will be usable for composing without mask_20_25.jpg when I dont need it.

Re: Fit one image on its place on another image

Posted: 2010-06-06T07:14:54-07:00
by snibgo
Your first command has two input images and one output file, so "convert" creates two output images. As tga files can store multiple images, this is what convert has done.

Code: Select all

identify user_photo_current_part.tga
shows that the file contains two images. Adding "-verbose" shows the first is RGB only, and the second is greyscale. Image viewers just show the first image. You can extract both images and view the resulting png files:

Code: Select all

convert user_photo_current_part.tga[0] tga0.png
convert user_photo_current_part.tga[1] tga1.png
Png files are single-image, and smaller than tga, so I generally prefer them.

Windows script, so change ^ to \ and ( to \(

Code: Select all

convert ..\user_photo_resized.tga ^
  -auto-level -brightness-contrast 0,4 ^
  -color-matrix ".788 0 0 0 .98 0 0 0 .996" ^
  mask_all.jpg ^
  -compose CopyOpacity -composite ^
  user_photo_current_part.png

convert "f0022.jpg" ^
  ( user_photo_current_part.png ^
    -virtual-pixel transparent -background none -gravity northwest ^
    -extent 768x432 ^
    -distort Perspective "0,0 549,22  300,0 604,122  300,400 439,194  0,400 397,97" ^
  ) ^
  mask_20_25.jpg -composite ^
  result.jpg
In the first command, I have explicitly "-compose CopyOpacity -composite" to make the corners transparent.

I have also broken up both commands into lines that show the logical structure.

Re: Fit one image on its place on another image

Posted: 2010-06-06T14:15:36-07:00
by Fludimir
Not even think about multiimage tga, thanks, now all works perfect

Re: Fit one image on its place on another image

Posted: 2010-06-06T18:11:50-07:00
by anthony
snibgo wrote:You can extract both images and view the resulting png files:

Code: Select all

convert user_photo_current_part.tga[0] tga0.png
convert user_photo_current_part.tga[1] tga1.png
Slightly faster is to use either -adjoin (save multi-images into separate files)

Code: Select all

  convert user_photo_current_part.tga -adjoin tga.tga
that creates a tga-0.tga and tga-1.tga

Or better still add '%d' to the output file name,...

Code: Select all

  convert user_photo_current_part.tga -adjoin tga_%03d.tga
whcih creates tga_000.tgz and tga_001.tgz

I have also broken up both commands into lines that show the logical structure.
Good to see! Makes reading the command far easier.

For more programming and scripting suggestions see
Hints for Better ImageMagick Shell/PHP Scripts
http://www.imagemagick.org/Usage/api/#scripts