[SOLVED] Multiple operations on an image

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
mike271828
Posts: 5
Joined: 2015-09-29T03:05:37-07:00
Authentication code: 1151

[SOLVED] Multiple operations on an image

Post by mike271828 »

I'd like to take a picture, then save the picture twice into memory after applying grayscale and 2colorthresh. Then I'd rotate the pics and save them. The 2colorthresh isn't a part of standard Imagemagick libs, therefor something like

Code: Select all

convert i.jpg -write mpr:i +delete \( mpr:i -colorspace Gray -write mpr:g  \)  \( mpr:i -2colorthresh +write mpr:2   \) \( mpr:g -rotate 10 -write x.jpg  \) \( mpr:2 -rotate 10 -write y.jpg  \)
can't be used? I'll need to split that into 2 statements, one for gray, one for 2color?
Last edited by mike271828 on 2015-09-29T10:01:53-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Multiple operations on an image

Post by snibgo »

Is "2colorthresh" something you wrote yourself? Is it compiled into IM as an ordinary operation?

IM can do two or more operations in sequence. As many as you want. You don't need to write after every operation. I've split this into lines for readability. Use whatever line-continuation escapes you need.

Code: Select all

convert
  i.jpg
  ( +clone
    -colorspace Gray
    -rotate 10
    -write x.jpg
    +delete
  )
  -2colorthresh
  -rotate 10
  y.jpg
snibgo's IM pages: im.snibgo.com
mike271828
Posts: 5
Joined: 2015-09-29T03:05:37-07:00
Authentication code: 1151

Re: Multiple operations on an image

Post by mike271828 »

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

Re: Multiple operations on an image

Post by snibgo »

Ah, well, that's a bash script. You can't run bash scripts within a convert command. You would run the script with i.jpg as the input file, then take the output and rotate it.

But that script is very simple. The processing is just "+dither -colors 2 -colorspace gray -contrast-stretch 0", so I expect you could put that in the command instead of "-colorthresh".
snibgo's IM pages: im.snibgo.com
mike271828
Posts: 5
Joined: 2015-09-29T03:05:37-07:00
Authentication code: 1151

Re: Multiple operations on an image

Post by mike271828 »

That's right, thanks a lot.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Multiple operations on an image

Post by fmw42 »

In this case my script is simple enough to decompose the commands. In general, for unix, you can pipe into and out of the script, thought that is still multiple converts. It only saves you writing intermediate output images to disk.
Post Reply