Page 1 of 2

How to work with files separately?

Posted: 2018-10-07T04:52:15-07:00
by imanasya
Is it possible to take 2 images, make some processing with them, then export them in 2 different variables (do not save to files) and then use these variables as inputs for other ImageMagic commands?

Re: How to work with files separately?

Posted: 2018-10-07T06:46:42-07:00
by snibgo
What type of variables? What is your script language? What version of IM?

You can write to "txt:" or non-compressed PNM format and save that in a bash variable:

Code: Select all

myimg=$(convert rose: txt:)
But there is a large overhead in converting to text and back. You should also consider using pipes, probably using IM's built-in "miff" format.

Re: How to work with files separately?

Posted: 2018-10-07T07:45:35-07:00
by imanasya
When I said "variables" I didn't mean txt. I meant saving images to some instances inside ImageMagic (save to RAM, not to hdd).

Re: How to work with files separately?

Posted: 2018-10-07T08:25:05-07:00
by snibgo
IM can images save to RAM for use later within the same command. But they can't be used in later commands. Memory and commands don't work that way.

You might consider a RAMdisk (eg see https://www.ghacks.net/2017/04/03/the-b ... r-windows/) or SSD.

Piping is a common technique.

Re: How to work with files separately?

Posted: 2018-10-07T10:00:38-07:00
by imanasya
I'm not sure that RAMdisk is the best for this case. Let me ask in another way. Lets say I have 3 input images: 1.jpg, 2.jpg, 3.jpg.
I'd like do increase the first one by 10%, then rotate it 90 degrees clockwise, then save it as out1.jpg.
The second image to reduce by 20%, then overlay it to right bottom corner of out1.jpg and save it to out2.jpg.
The third one combine horizontally with 1.jpg (original) and out2.jpg using +append.

How does ImageMagic line will look like?

Re: How to work with files separately?

Posted: 2018-10-07T10:23:24-07:00
by fmw42
See parenthesis processing and clones. You should be able to do that all in one command.

https://imagemagick.org/Usage/basics/#parenthesis
https://imagemagick.org/Usage/basics/#clone

If I understand your request, try this (unix syntax)

Code: Select all

convert \( 1.jpg -resize 110% -rotate 90 \) \
\( +clone \( 2.jpg -resize 80% \) -gravity southeast -compose over -composite \) \
3.jpg \
+gravity +append \
result.jpg
___________________________

Helpful pages:

http://www.imagemagick.org/discourse-se ... f=1&t=9620
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
https://github.com/ImageMagick/usage-markdown

Re: How to work with files separately?

Posted: 2018-10-07T10:29:52-07:00
by imanasya
fmw42, thank you

Re: How to work with files separately?

Posted: 2018-10-07T10:31:11-07:00
by imanasya
How does this " \( " change in windows?

Re: How to work with files separately?

Posted: 2018-10-07T10:32:25-07:00
by fmw42
See my edits above. For windows, remove the \s with the \( and for the end of line \ change to ^

see https://imagemagick.org/Usage/windows/

Re: How to work with files separately?

Posted: 2018-10-07T10:33:27-07:00
by snibgo
Fred's version doesn't save out1.jpg and out2.jpg. But I'm not sure if you really wanted that.

Re: How to work with files separately?

Posted: 2018-10-07T10:36:15-07:00
by imanasya
Is it possible to do several out files?

Re: How to work with files separately?

Posted: 2018-10-07T11:09:13-07:00
by snibgo
Insert "+write out1.jpg" or whatever.

Re: How to work with files separately?

Posted: 2018-10-07T11:14:14-07:00
by imanasya
Here in brackets?

Code: Select all

convert \( 1.jpg -resize 110% -rotate 90 +write out1.jpg \) \
\( +clone \( 2.jpg -resize 80% +write out2.jpg \) -gravity southeast -compose over -composite \) \
3.jpg \
+gravity +append \
result.jpg
What does +write do?

Re: How to work with files separately?

Posted: 2018-10-07T11:18:44-07:00
by snibgo

Re: How to work with files separately?

Posted: 2018-10-07T11:25:38-07:00
by imanasya
Thank you