Extract Clipping 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?".
ckunchala
Posts: 8
Joined: 2020-01-29T11:08:28-07:00
Authentication code: 1152

Extract Clipping Image

Post by ckunchala »

Hi Experts,

Need your inputs in the following requirement.

IM Version: ImageMagick 7.0.8-3 Q16 x64 2018-06-24
OS: Windows

Requirement: To get the clip from the image "only if found" and apply background color with grey.

Image link: http://img.buzzram.de/uploads/1584707760age.jpg

i have tried following command,

magick source.JPG -clip -background grey clip_path.JPG

But,
1) its not working if source image doesn't have clip define.
2) if source image has clips defined it it, i don't see any error but background color not applying.

can anyone help me with the command which should work even if clip available or not.

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

Re: Extract Clipping Image

Post by fmw42 »

You should be able to do that with

Code: Select all

magick 1584707760age.jpg -alpha transparent -clip -alpha opaque -strip 1584707760age_clip.png
But for me on IM 7.0.10.1 Q16 Mac OSX, it does an abort trap 6.

User avatar
magick
Site Admin
Posts: 11254
Joined: 2003-05-31T11:32:55-07:00

Re: Extract Clipping Image

Post by magick »

Its possible Mac OSX is killing your process because its using too much memory. Try this command instead:

Code: Select all

convert -limit area 2MiB 1584707760age.jpg -alpha transparent -clip -alpha opaque -strip 1584707760age_clip.png

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

Re: Extract Clipping Image

Post by fmw42 »

Still the same -- abort trap

Code: Select all

magick -limit area 2MiB 1584707760age.jpg -alpha transparent -clip -alpha opaque -strip 1584707760age_clip.png
Abort trap: 6

User avatar
magick
Site Admin
Posts: 11254
Joined: 2003-05-31T11:32:55-07:00

Re: Extract Clipping Image

Post by magick »

Your command works runs to completion without complaint on our Mac OSX Powerbook with the latest OS and XCode release installed. We tried the latest releases of ImageMagick version 6 & 7.

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

Re: Extract Clipping Image

Post by fmw42 »

This fails with abort trap 6 when using the default Inkscape:

magick identify -quiet -format "%[8BIM:1999,2998:#1]" 1584707760age.jpg |\
magick -quiet 1584707760age.jpg +repage \
\( -density 96 - -channel rgb -negate -blur 0x1 -level 50x100% +channel \) \
-alpha off -compose copy_opacity -composite \
1584707760age_clip.png

But this works when using MSVG:

magick identify -quiet -format "%[8BIM:1999,2998:#1]" 1584707760age.jpg |\
magick -quiet 1584707760age.jpg +repage \
\( -density 96 MSVG:- -channel rgb -negate -blur 0x1 -level 50x100% +channel \) \
-alpha off -compose copy_opacity -composite \
1584707760age_clip.png

So I would say that the issue might be with Inkscape 0.92.4_11

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

Re: Extract Clipping Image

Post by snibgo »

The input JPEG is CMYK, with an embedded profile. If you want a sRGB output, you should use "-profile" to convert it. After making the non-clipped area transparent, we can flatten against gray:

Code: Select all

magick 1584707760age.jpg -alpha transparent -clip -alpha opaque -profile sRGB.icc -background Gray -layers Flatten out.png
This works fine with IM 7.0.8-64 and Inkscape 0.91 on Windows 8.1, using a peak of about 2 GB memory.

I don't think any single IM command will cope with both clip and non-clip inputs. You could use this command for all inputs, and if it fails with "no clip path defined" error, then use a simpler command.
snibgo's IM pages: im.snibgo.com

User avatar
magick
Site Admin
Posts: 11254
Joined: 2003-05-31T11:32:55-07:00

Re: Extract Clipping Image

Post by magick »

See if the problem is inkscape. Try these commands:

Code: Select all

magick identify -quiet -format "%[8BIM:1999,2998:#1]" 1584707760age.jpg > test.svg
inkscape test.svg --export-file='test.png' --export-dpi=96 --export-background='rgb(100%,100%,100%)' --export-background-opacity=1 > test.log
Note, if your inkscape version is < 1.0, change --export-file to --export-png.

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

Re: Extract Clipping Image

Post by fmw42 »

I get for Inkscape 0.92.4_11 on Mac OSX Sierra (using --export-png)

Code: Select all

magick identify -quiet -format "%[8BIM:1999,2998:#1]" 1584707760age.jpg > test.svg
inkscape test.svg --export-png='test.png' --export-dpi=96 --export-background='rgb(100%,100%,100%)' --export-background-opacity=1 > test.log
dbus[671]: Dynamic session lookup supported but failed: launchd did not provide a socket path, verify that org.freedesktop.dbus-session.plist is loaded!
Failed to get connection
** (inkscape:671): CRITICAL **: 10:10:05.917: dbus_g_proxy_new_for_name: assertion 'connection != NULL' failed

** (inkscape:671): CRITICAL **: 10:10:05.917: dbus_g_proxy_call: assertion 'DBUS_IS_G_PROXY (proxy)' failed

** (inkscape:671): CRITICAL **: 10:10:05.918: dbus_g_connection_register_g_object: assertion 'connection != NULL' failed

The log lists:

Code: Select all

DPI: 96
Background RRGGBBAA: ffffffff
Area 0:0:4912:7360 exported to 4912 x 7360 pixels (96 dpi)
Bitmap saved as: test.png

ckunchala
Posts: 8
Joined: 2020-01-29T11:08:28-07:00
Authentication code: 1152

Re: Extract Clipping Image

Post by ckunchala »

Hi Experts,

Thank you so much for taking time and providing your valuable inputs.

Tried @snibgo's reply and it worked fine but again i have couple of further questions.

1) i need to make the background color as 25% transparent.
2) we're using the following command to generate preview of image, now what i'm looking is, first we need to extract the clip out of image and apply the following command for the preview.

-intent relative -sample 1024x768> -quality 95 -colorspace sRGB -strip -auto-orient

Thanks a Million in advance !!!

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

Re: Extract Clipping Image

Post by snibgo »

1) I flattened against "-background Gray". Instead of "Gray", use whatever colour you want, eg "srgba(50%,50%,50%,0.75)".

2) I don't understand your question. Is it a question?
snibgo's IM pages: im.snibgo.com

ckunchala
Posts: 8
Joined: 2020-01-29T11:08:28-07:00
Authentication code: 1152

Re: Extract Clipping Image

Post by ckunchala »

Yes @snibgo,

my question is how to combine/merge below 2 commands

-intent relative -sample 1024x768> -quality 95 -colorspace sRGB -strip -auto-orient

-alpha transparent -clip -alpha opaque -profile sRGB.icc -background Gray -layers Flatten

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

Re: Extract Clipping Image

Post by snibgo »

Those are not two complete commands. Commands would start with "magick", and would need input and output files.

I guess you want them in the opposite order? Maybe:

Code: Select all

magick 1584707760age.jpg -alpha transparent -clip -alpha opaque -profile sRGB.icc -background Gray -layers Flatten out1.png

magick out1.png -intent relative -sample 1024x768> -quality 95 -colorspace sRGB -strip -auto-orient out2.png

But "-intent" is a setting for "-profile", so must come before it. And "-colorspace sRGB" isn't relevant if the image is already sRGB.

Do you want to keep the intermediate result, out1.png?
snibgo's IM pages: im.snibgo.com

ckunchala
Posts: 8
Joined: 2020-01-29T11:08:28-07:00
Authentication code: 1152

Re: Extract Clipping Image

Post by ckunchala »

Hi Snibgo,

i'm sorry, i just didnt mentioned the magick , input file and output file as you can understand by looking at provided commands. i will provide complet commands next time.

yes you are correct, i need to extract the clip first (as like 1st command) and then apply 2nd command for the preview. is it possible to combine both commands into single command?

also, why do we need to keep output file as PNG ? can't we keep it as JPG? Any specific reason to keep result in PNG ?

Thanks Million !!!

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

Re: Extract Clipping Image

Post by fmw42 »

If you have a clipping path, it is usually to make something transparent. JPG does not support transparency. So you either need to flatten the result against some color or you will get black where the transparency would be with JPG. TIFF also supports transparency. So you could use PNG or TIFF

Locked