I am trying to composite several images into single image using convert and -flatten. I need to specify certain position for every image. While I used only static files everything worked fine:
convert -size 240x320 \
> -page +0+0 Idle_Background.template.png \
> -page +85+8 .template.color-text-screen-title.png \
...
> -page +0+299 .template.color-text-softkeys-idle.png \
> -flatten -resize 180x240 -quality 100 screen.0.jpg
With this construction I got exactly what I expected. Then it became necessary to add a cropped image into the image queue. The source image that is cropped is:
Digital_Clock.template.png PNG 130x57 130x57+0+0 8-bit DirectClass 1.88kb
From this image I need to crop 53x57+0+0 area and place it on resulting image at position +21+1.
In version 6.4.4 the following construction was used to achieve the desired result:
convert -size 240x320 \
> -page +0+0 Idle_Background.template.png \
> -page +85+8 .template.color-text-screen-title.png \
...
> -page +0+299 .template.color-text-softkeys-idle.png \
> -page +21+1 \( Digital_Clock.template.png -crop 74x58-21-1\! +repage \) \
> -flatten -resize 180x240 -quality 100 screen.0.jpg
I don't fully understand why did it work, but at least it produced the expected result - correct piece of digital clock was placed at +21+1 on resulting image. After update to the version 6.4.7 this construction produces not exactly what I want: cropped piece of digital clock has lesser width that required and is positioned at +0+0. If I change "-page +21+1" to "-page +0+0" it gets cropped correctly but still is positioned at +0+0. I tried different things but did not succeed to place the cropped image at +21+1.
My question is: in given conditions what should I do to place the cropped piece of specified image to position +21+1 from upper left corner of the resulting image? Maybe I wrongly understand how both the -page and parenthesis work?
Problems with -flatten cropped image in version 6.4.7
Re: Problems with -flatten cropped image in version 6.4.7
Seems like I found the solution:
-page +0+0 \( Digital_Clock.template.png -crop 53x57+0+0 +repage -repage 53x57+21+1 \) \
-page +0+0 \( Digital_Clock.template.png -crop 53x57+0+0 +repage -repage 53x57+21+1 \) \
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Problems with -flatten cropped image in version 6.4.7
You don't need the +repage, and the -repage will do the job as it is fully specified.
Note that -flatten gets the final image size from the canvas page size of just the first image. as such you don't need to change the image size in the -repage either, just set the image offset.
Also not you can do relative offsets from original crop position too by using a \! flag in the -repage argument. The \! in the crop argument however also does this though as a 'viewport' window rather than an offset, so the position in crop is a negative.
Read the individual operations in IM examples Crop Viewport
http://www.imagemagick.org/Usage/crop/#crop_viewport
as well as the raw notes on image pages offsets in
http://www.imagemagick.org/Usage/basics/#page
You may also like to look at the animation stuff which is also relativant. An animation in IM is treated exactly like a layered image, except the images are not flattened, but have time and dispose components.
http://www.imagemagick.org/Usage/anim_m ... e_relative
Note that -flatten gets the final image size from the canvas page size of just the first image. as such you don't need to change the image size in the -repage either, just set the image offset.
Also not you can do relative offsets from original crop position too by using a \! flag in the -repage argument. The \! in the crop argument however also does this though as a 'viewport' window rather than an offset, so the position in crop is a negative.
Read the individual operations in IM examples Crop Viewport
http://www.imagemagick.org/Usage/crop/#crop_viewport
as well as the raw notes on image pages offsets in
http://www.imagemagick.org/Usage/basics/#page
You may also like to look at the animation stuff which is also relativant. An animation in IM is treated exactly like a layered image, except the images are not flattened, but have time and dispose components.
http://www.imagemagick.org/Usage/anim_m ... e_relative
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/