Page 1 of 1
Positioning images using FX calcs
Posted: 2013-04-11T15:28:38-07:00
by emontezuma
Hi Imagemagick friends.
I have an issue, can you help me?
1) I'm trying to create an image with 3 pictures in a single command line.
2) The first image will contain the next 2 images. In my program I don't know the images sizes, the program calculates them depend of the screen setup.
3) The news 2 images positions and sizes will depend of the first image size.
4) How can I get the width and height of the first image in the same commad line wich I resize the first image? I have read a lot of documentations but nothing work. Is there a way to calcs the width and heigth on the air?
5) I am ussing VB6 and batch DOS files to create and manage ImageMagick convert command, but I have no good result.
Best regards for everyone.
Re: Positioning images using FX calcs
Posted: 2013-04-11T16:53:56-07:00
by snibgo
I'm not clear what you are doing. What commands do you use currently?
In Windows, I generally find image dimensions like this:
Code: Select all
FOR /F "tokens=1,2" %%i IN ('identify -ping -format "%%w %%h" image.png') DO (
set WIDTH=%%i
set HEIGHT=%%j
)
Re: Positioning images using FX calcs
Posted: 2013-04-11T19:09:45-07:00
by fmw42
I do not think you can get the resized image dimensions and use them in the same command line. But it really depends upon what you are doing. In unix, you can fake it out with a command line imbedded within a command line. I don't know about Windows. Nevertheless, there are very few ways to make use of that kind of information within the same command line.
see
http://www.imagemagick.org/Usage/basics/#set
and its following sections.
Only distort viewport and a few other functions can take such inline data and make use of it in IM6. In IM7 it will be more flexible to use such calculations in the same command line.
Perhaps you could show us a bit more of what you are trying to do with some code examples or a diagram or further details.
Re: Positioning images using FX calcs
Posted: 2013-04-11T21:25:53-07:00
by anthony
You can do it in one command using a special 'layering' technique. Specifically you would use -set page '...' to set the location of the image before 'layering' the image into the right location.
The 'page' properity is used to set the virtual offset of an image. it is the lower level equivalent of using -repage.
IMv7 "magick" command will eventually let you use Escape sequences (such as %[fx:...] calculations in all arguments, but at the moment only 'operators' have that ability.
Re: Positioning images using FX calcs
Posted: 2013-04-12T10:57:53-07:00
by emontezuma
Thanks everyone for your support.
I mean:
1) I have a single image called "c:\image1.png" this image will be resized from 200x200 to 100x100.
2) I have another image called "c:\logo.png" this other image will be resized too but it size will depend of the first image's size.
I had though something like that (DOS command line)
convert "c:\image1.png" resize "100x100" ( "c:\logo.png" resize "%[fx:%w * 0.25]x%[fx:%h * 0.25]" -gravity north ) -composite "c:\image3.png"
My code is more complex but in fact my goal is seems to this command line.
As you can see I need to nkow the new size of the first image in order to calc the second image's size.
Snibgo: I don't know as well the DOS code
... Please, can you translate your code
"... FOR /F "tokens=1,2" %%i IN ('identify -ping -format "%%w %%h" image.png') DO (
set WIDTH=%%i
set HEIGHT=%%j
)..."
to my sample?
Can you swap the variables for the file names?
Best regards...
Re: Positioning images using FX calcs
Posted: 2013-04-12T13:11:39-07:00
by snibgo
I think this must be done in three stages.
1. Resize first file.
2. Find new dimensions of that file, each multiplied by 0.25.
Code: Select all
FOR /F "tokens=1,2" %%i in ('identify -format "%%[fx:w*0.25] %%[fx:h*0.25]" new_first.png') DO (
set NEWWI=%%i
set NEWHT=%%j
)
3. Resize the second file and composite the two together.
Re: Positioning images using FX calcs
Posted: 2013-04-12T13:34:00-07:00
by emontezuma
Thanks snibgo.
Excume me by my small knowledge about DOS... but I cant see in your code the filename of the two image...
"FOR /F "tokens=1,2" %%i in ('identify -format "%%[fx:w*0.25] %%[fx:h*0.25]" new_first.png') DO (
set NEWWI=%%i
set NEWHT=%%j
)"
I coludnt read all the images directory because there are a lot of images, I would like to know the size about one single image, into your sample, where I will put the image1 file name?.
In addition, the app maybe will process around 1000 images per minute, for this reason I would like to minimize the processess number and make large command lines.
Re: Positioning images using FX calcs
Posted: 2013-04-12T14:11:05-07:00
by snibgo
Step 1: Resize the first image to fit in a 100x100 box. Call the result, for example, new_first.png.
Step 2: My code shows how to get the actual size of new_first.png.
Step 3: Resize the second image and composite the two resized images together.
If you are concerned about speed, DOS script is slow. On an ordinary PC, I doubt you could do this 1000 times in one minute. A compiled program might, and would certainly be faster than DOS script.
Re: Positioning images using FX calcs
Posted: 2013-04-12T14:21:48-07:00
by emontezuma
Friends... good news
thanks for your support I did the necessary code to obtain the %w and %h using the snibgo sample.
Best regards.