[SOLVED] How to copy-paste an image region with MSL?

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?".
Post Reply
magmical
Posts: 30
Joined: 2013-05-03T05:31:05-07:00
Authentication code: 6789

[SOLVED] How to copy-paste an image region with MSL?

Post by magmical »

Hi folks

I want to copy-paste an image region with Magick Scripting Language.

With convert it must look like this:
convert old.png ( +clone -crop 20x20+10+10 +repage ) -geometry +110+110 -composite new.png

How can I do this with Magick Scripting Language?
My real problem ist how to do a clone?
Last edited by magmical on 2013-05-20T04:35:06-07:00, edited 2 times in total.
magmical
Posts: 30
Joined: 2013-05-03T05:31:05-07:00
Authentication code: 6789

Add: How to copy-paste an image region with MSL?

Post by magmical »

After a few trials - this code does a copy-paste-like action:

Code: Select all

<group>
	<image id="clone">		
		<read filename="source.gif"/>
		<crop geometry="... />
		<repage geometry="0x0+0+0" />
	</image>
	<image>
		<read filename="source.gif"/>
		<composite image="clone" geometry="..." />
		<write filename="out.png"/>
	</image>
</group>
It's works pretty good but it's not perfect:
it loads the "source.gif" 2 times.

Any other way to do this?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to copy-paste an image region with MSL?

Post by anthony »

Nope that would be the way... crop to copy, compose to paste

Though you should be able to make a clone of the original image rather than read it in twice.

One way, if you can't find a 'clone', would be read in image, write to a 'MPR:' image store, then when needed again read from that store.

See IM examples MPR (though that is command line)
http://www.imagemagick.org/Usage/files/#mpr
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
magmical
Posts: 30
Joined: 2013-05-03T05:31:05-07:00
Authentication code: 6789

Re: How to copy-paste an image region with MSL?

Post by magmical »

Clone seems to be missing in MSL.
<clone /> throws an error:
conjure.exe: unrecognized element `clone' @ error/msl.c/MSLStartElement/2275.


But the idea with mpr (memory program register) is really good! Thanks.

This code reads the image only once.

Code: Select all

<group>
	<image>		
		<read filename="source.gif"/>
		<write filename="mpr:source" />
	</image>

	<image id="part">		
		<read filename="mpr:source"/>
		<crop geometry="520x100+0+0" />
		<repage geometry="0x0+0+0" />
	</image>

	<image>
		<read filename="mpr:source"/>
		<composite image="part" geometry="0x0+0+100" />
		<write filename="out.png"/>
	</image>
</group>
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: [SOLVED] How to copy-paste an image region with MSL?

Post by anthony »

You can combine part 1 and 2.

But other than that looks good.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
magmical
Posts: 30
Joined: 2013-05-03T05:31:05-07:00
Authentication code: 6789

Re: [SOLVED] How to copy-paste an image region with MSL?

Post by magmical »

anthony wrote:You can combine part 1 and 2.
Well, thats another good aspect! Looks much clearer now! :D

Code: Select all

<group>
   <image id="part">      
      <read filename="source.gif"/>
      <write filename="mpr:source" />
      <crop geometry="520x100+0+0" />
      <repage geometry="0x0+0+0" />
   </image>

   <image>
      <read filename="mpr:source"/>
      <composite image="part" geometry="0x0+0+100" />
      <write filename="out.png"/>
   </image>
</group>
Perfect! :D

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

Re: [SOLVED] How to copy-paste an image region with MSL?

Post by anthony »

NP.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply