negative x y co-ords for image placement
negative x y co-ords for image placement
Hi,
How do I specify placement of an image on a canvas at negative x y co-ords e.g placing a 100x100 image at -34, -45 so that it is only partially visible on the canvas.
I would like to be able to do this using the simple -page command but +-34+-45 does not seem to be acceptable..
OR can you specify the co-ords to refer to another part of the image being place rather than 0,0 so that I could use positive values for the position on canvas and specify it aligning with a point say (in the -34.-55 example used) at 68,55 on the image being placed?
Many thanks for any help.
How do I specify placement of an image on a canvas at negative x y co-ords e.g placing a 100x100 image at -34, -45 so that it is only partially visible on the canvas.
I would like to be able to do this using the simple -page command but +-34+-45 does not seem to be acceptable..
OR can you specify the co-ords to refer to another part of the image being place rather than 0,0 so that I could use positive values for the position on canvas and specify it aligning with a point say (in the -34.-55 example used) at 68,55 on the image being placed?
Many thanks for any help.
Re: negative x y co-ords for image placement
Excuse typo in above..co-ords for alignment shift example should read
"(in the -34.-55 example used) at 66,45 on the image being placed?"
"(in the -34.-55 example used) at 66,45 on the image being placed?"
Re: negative x y co-ords for image placement
I thought negative values worked but I can not try it at the moment.
How about starting with a larger canvas and then cropping it ?
How about starting with a larger canvas and then cropping it ?
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: negative x y co-ords for image placement
\( image.png -repage -34-55 \)
will do the job of giving the image a negative position.
however if you want it to 'clip' to the background image you should use -flatten, whcih will not expand the first image.
or use -geometry -34-55 -composite method instead.
try giving us the complete simplified command of what you are attempting.
will do the job of giving the image a negative position.
however if you want it to 'clip' to the background image you should use -flatten, whcih will not expand the first image.
or use -geometry -34-55 -composite method instead.
try giving us the complete simplified command of what you are attempting.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: negative x y co-ords for image placement
Thanks for that - much appreciated.
The first problem was that I was trying to get it to accept +-34+-55. but as per your example it will work with -34-55..
The problem occurred because I am using variables for the co-ords - so now I am trying to solve it by adding in the plus sign only when positive but it is reverting again to 0,0 positioning.. please see code example (from within php exec)..
When I put values in manually say -300-300 it works fine but the variable using line is putting the image at 0,0 -->
The first problem was that I was trying to get it to accept +-34+-55. but as per your example it will work with -34-55..
The problem occurred because I am using variables for the co-ords - so now I am trying to solve it by adding in the plus sign only when positive but it is reverting again to 0,0 positioning.. please see code example (from within php exec)..
When I put values in manually say -300-300 it works fine but the variable using line is putting the image at 0,0 -->
Code: Select all
$x = "-200";
if ($x < 0)
{
$op_x = "";
}
else
{
$op_x = "+";
}
$y = "-200";
//comment - just use op_x for now to test
exec ("convert -size 1000x1000 xc:skyblue \\
-page $op_x . $x . $op_y. $y image.png \\
-page -300-300 image.png \\
-flatten painted_canvas.png");
Re: negative x y co-ords for image placement
..sorry..
code does only use $op_x for testing --
code does only use $op_x for testing --
Code: Select all
$x = "-200";
if ($x < 0)
{
$op_x = "";
}
else
{
$op_x = "+";
}
$y = "-200";
exec ("convert -size 1000x1000 xc:skyblue \\
-page $op_x . $x . $op_x. $y image.png \\
-page -300-300 image.png \\
-flatten painted_canvas.png");
Re: negative x y co-ords for image placement
..sorry again,,
that code was missing quotes to parse php code within the exec..so..
unless some wise programmer can tell me how to assign the operator more simply in php
..seems to work now..
so solved thanks --
ta
that code was missing quotes to parse php code within the exec..so..
unless some wise programmer can tell me how to assign the operator more simply in php
..seems to work now..
so solved thanks --
ta
Re: negative x y co-ords for image placement
I can not test this at the moment but something like this should work:
Search google for "php simple if" or "php ternary"
Code: Select all
$op_x = ($x < 0) ? $x: '"+".$x';
Re: negative x y co-ords for image placement
It should be:
Code: Select all
$op_x = ($x < 0) ? $x: "+".$x;
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: negative x y co-ords for image placement
The simplest way to handle this is either.
- Look at the number string and if you see no '-' then add a '+' to the number string.
That is similar to what the others have specified. - An even easier way is to use the printf() number format with a '+' sign in it.
For example printf("%+d%+d", x, y)
This tells the function to always include a sign with that number. It lets you do BOTH numbers and/or format the WHOLE geometry-style argument completely all in one go.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/