Positioning images using FX calcs

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Locked
emontezuma
Posts: 19
Joined: 2011-09-28T10:17:45-07:00
Authentication code: 8675308

Positioning images using FX calcs

Post 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.

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Positioning images using FX calcs

Post 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
)
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Positioning images using FX calcs

Post 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.

User avatar
anthony
Posts: 8884
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Positioning images using FX calcs

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

emontezuma
Posts: 19
Joined: 2011-09-28T10:17:45-07:00
Authentication code: 8675308

Re: Positioning images using FX calcs

Post 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...

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Positioning images using FX calcs

Post 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.
snibgo's IM pages: im.snibgo.com

emontezuma
Posts: 19
Joined: 2011-09-28T10:17:45-07:00
Authentication code: 8675308

Re: Positioning images using FX calcs

Post 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.

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Positioning images using FX calcs

Post 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.
snibgo's IM pages: im.snibgo.com

emontezuma
Posts: 19
Joined: 2011-09-28T10:17:45-07:00
Authentication code: 8675308

Re: Positioning images using FX calcs

Post 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.

Locked