How to work with files separately?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
imanasya
Posts: 36
Joined: 2018-10-05T11:21:07-07:00
Authentication code: 1152

How to work with files separately?

Post 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?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to work with files separately?

Post 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.
snibgo's IM pages: im.snibgo.com
imanasya
Posts: 36
Joined: 2018-10-05T11:21:07-07:00
Authentication code: 1152

Re: How to work with files separately?

Post 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).
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to work with files separately?

Post 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.
snibgo's IM pages: im.snibgo.com
imanasya
Posts: 36
Joined: 2018-10-05T11:21:07-07:00
Authentication code: 1152

Re: How to work with files separately?

Post 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?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to work with files separately?

Post 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
imanasya
Posts: 36
Joined: 2018-10-05T11:21:07-07:00
Authentication code: 1152

Re: How to work with files separately?

Post by imanasya »

fmw42, thank you
imanasya
Posts: 36
Joined: 2018-10-05T11:21:07-07:00
Authentication code: 1152

Re: How to work with files separately?

Post by imanasya »

How does this " \( " change in windows?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to work with files separately?

Post 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/
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to work with files separately?

Post by snibgo »

Fred's version doesn't save out1.jpg and out2.jpg. But I'm not sure if you really wanted that.
snibgo's IM pages: im.snibgo.com
imanasya
Posts: 36
Joined: 2018-10-05T11:21:07-07:00
Authentication code: 1152

Re: How to work with files separately?

Post by imanasya »

Is it possible to do several out files?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to work with files separately?

Post by snibgo »

Insert "+write out1.jpg" or whatever.
snibgo's IM pages: im.snibgo.com
imanasya
Posts: 36
Joined: 2018-10-05T11:21:07-07:00
Authentication code: 1152

Re: How to work with files separately?

Post 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?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to work with files separately?

Post by snibgo »

snibgo's IM pages: im.snibgo.com
imanasya
Posts: 36
Joined: 2018-10-05T11:21:07-07:00
Authentication code: 1152

Re: How to work with files separately?

Post by imanasya »

Thank you
Post Reply