Page 1 of 1

New page with gravity

Posted: 2011-07-29T01:24:05-07:00
by zipicip
Hello.

I have a script that compose 2 images for an animation

convert -dispose previous -delay 200 \
-page 300x169+0+0 1_tmp.png \
-page 300x169+0+0 2_tmp.png \
-loop 0 animation.miff


The images are smaller than the 300x169 new canvas and I want that the two images to be centered in the new canvas


convert -dispose previous -delay 200 \
-page 300x169+0+0 -gravity center 1_tmp.png \
-page 300x169+0+0 -gravity center 2_tmp.png \
-loop 0 animation.miff


This doesn't work.

Another idea if I cannot use gravity is to try to get for each image current width and put margin

Ex. ... if the image width = 200, canvas_width = 300 , I get -page 300x169+50+0 .... but I don't know how to rewrite the line so I can get half of the current image width

Re: New page with geometry

Posted: 2011-07-29T02:30:17-07:00
by Bonzo
Try -gravity:

Code: Select all

convert -dispose previous -delay 200 \
 -page 300x169+0+0 -gravity center 1_tmp.png \
 -page 300x169+0+0 -gravity center 2_tmp.png \
 -loop 0 animation.miff

Re: New page with geometry

Posted: 2011-07-29T05:05:26-07:00
by zipicip
my mistake from the beginning I was meaning gravity .... so already tried

Re: New page with gravity

Posted: 2011-07-29T09:41:41-07:00
by fmw42
-page is not to my knowledge gravity sensitive. It is something that I have been asking for in IM 7 or something like that under the appropriate conditions.

see comment at http://www.imagemagick.org/Usage/layers/#flatten

Use convert ... -gravity ... -geometry ... -compose ... -composite

see http://www.imagemagick.org/Usage/layers/#convert

Re: New page with gravity

Posted: 2011-07-31T23:06:14-07:00
by anthony
-page which is defining virtual canvases does NOT make use of gravity! It is not part of the definition of virtual canvases (from GIF animation), or image layering (from GIMP and photoshop). The meaning of virtual canvas and the offset of the image is very clear and well defined. (virtual canvas is positioning canvas size relatitve to the origin 0,0, while the offset is simply a positive direction offset from that fixed 0,0 origin to the top level corner of the image.


However using -geometry to define composition offsets does allow the use of gravity to define the meaning of the offset, as a spacing between an image and another image (edges, corners, or middles) that is typically larger image (though not always).

What is currently NOT defined (and has been requested MANY times) is a justification of the image relative to the specified gravity defined offset (defaulting to same direction as the gravity definition, unless changed). This is one of the features that I want added to IMv7!

Re: New page with gravity

Posted: 2011-07-31T23:25:48-07:00
by zipicip
ok... Thanks a lot.

I have another question:

I use php to execute exec commands like:

exec ("convert -size 300x250 gradient:" . $gradient_up . "-" . $gradient_down . " canvas_300x250.png");

The command above works fine.

The problem:

I want to compose in a php string multiple imagick commands so when a have all commands I need in one string to execute at the end of the program

exec (all_imagick_comands);

But this doesn't execute right

For example:

$frame = '';
foreach ($array as $image) {
$frame .= " -page 300x250+0+0 imagine_name_" . $image . "_300x250.png \ \n";
}

exec (" convert -dispose previous -delay 200 \
" .$frame . "
-loop 0 animation.miff ");

I am missing something ?

Re: New page with gravity

Posted: 2011-08-01T00:35:05-07:00
by zipicip
I managed to do this

the mistake: I was adding a space after slash or new line before command end.

Re: New page with gravity

Posted: 2011-08-01T00:40:05-07:00
by anthony
IM convert can do all the convert commands in one command. Even if it means deleteing the image you have finished and written out, and starting with a new image. Nothing stops you from doing this.

the problem is if you need to do some shell programming between steps.

However PHP exec() string is actually just a shell script. You can have mulpile commands or even shell if-then or loops in it. Just follow normal shell scripting, but adding newlines or ';' between the individual commands.

Eg:

Code: Select all

  exec("command args; command args; command args");

Re: New page with gravity

Posted: 2011-08-04T00:19:59-07:00
by zipicip
another question regarding resizing an image.

I have an area let say: 145x115

Some images are portrait and some are landscape.

So I want an image size to fit this area.

The problem:

If I use

$this->max_width_image = '145';
$this->max_height_image = '115';

convert image.png -resize " . $this->max_width_image . "x\> image_tmp.png
convert image.png -resize x". $this->max_height_image . "\> image_tmp.png

This will resize to smallest height. This is not good. I just only to resize to width or height only if necessary.

Let say after first resize image has 145x200 . Only then I want to lose from width so can fit area. The problem here if initial width is smaller than height the image will be resized to width first.

So I need to know first the image width and height. But I don't know how to use that with exec from php.

Re: New page with gravity

Posted: 2011-08-04T00:51:22-07:00
by zipicip
I guess I managed myself

img_width=identify -format '%w' image.png
img_height=identify -format '%h' image.png


if [ {img_width} -eq {img_height} ]
then
convert image.png -resize x". $this->max_height_imagine . "\> image.png
elif [ {img_width} -gt {img_height} ]
then
convert image.png -resize x". $this->max_width_imagine . "\> image.png
convert image.png -resize x". $this->max_height_imagine . "\> image.png
else
convert image.png -resize x". $this->max_height_imagine . "\> image.png
convert image.png -resize x". $this->max_width_imagine . "\> image.png
fi

Re: New page with gravity

Posted: 2011-08-04T16:56:04-07:00
by anthony
zipicip wrote:I have an area let say: 145x115
Some images are portrait and some are landscape.
So I want an image size to fit this area..
That is automatic defaults for resize! Just resize the image to 145x115 and the image will fit into that area!
No need to do the tests yourself, just do it!

See Resize examples...
http://www.imagemagick.org/Usage/resize/#resize