Convert the background of an image to transparent

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
laxmi131
Posts: 9
Joined: 2017-04-05T07:01:17-07:00
Authentication code: 1151

Convert the background of an image to transparent

Post by laxmi131 »

hello All,
I want to perform 3 steps in a single convert comaand

1. convert the image from CMYK to RGB
2. convert the background of a image to transparent
3.convert image to png.

Code: Select all

convert  -profile <path>\CoatedFOGRA27.icc -profile <path>\sRGB_v4_ICC_preference.icc -resample 300x300 -depth 8 "%1"[0] -fuzz 10% -transparent white -flatten -resize 1260x1260 -quality 80 "%2"
I also tried below command:

Code: Select all

convert  -profile <path>\CoatedFOGRA27.icc -profile <path>\sRGB_v4_ICC_preference.icc -resample 300x300 -depth 8 "%1"[0] -background none -flatten -resize 1260x1260 -quality
80 "%2"

I am able to convert the image to RGB and also generate a .png file but using the above script background is not converted to transparent. Can you please let me know the Imagemagick script for converting the background. the source file which I am using is a .eps

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

Re: Convert the background of an image to transparent

Post by snibgo »

What version IM do you use? On what platform? If Windows BAT, you should double the % in "-fuzz 10%".

The correct syntax is: read the image; process it; write the output. So the "profiles" and "-resample" should be after the input file, not before it.

After the resample, what colour is the background? You want to make that colour transparent, yes? If it was white, than "-transparent White" will do that.

Why do you "-background none -flatten"? What does that do?
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert the background of an image to transparent

Post by fmw42 »

User snibgo has some good points. Furthermore ...

Perhaps you should post one of your input images? What format is it? Is it transparent or not? Why do you do -resample and also -resize? You should do just one or the other. You can do -resize alone and then set the density you want, if you want a certain pixel dimension and a certain print size.
laxmi131
Posts: 9
Joined: 2017-04-05T07:01:17-07:00
Authentication code: 1151

Re: Convert the background of an image to transparent

Post by laxmi131 »

Hi
Thank you for responding , we use "ImageMagick-6.6.9-Q16". I use this imagemagic script in media manger. this script is defined in a pipeline of media manger and hence I have not specified the input and output file. my input file will be .eps and the output file will be .png . media manager pipeline take caes of converting the image from .eps to .png .

The output image should be of 300 dpi ( for that I used -resample 300x300) , image should have size 1260x1260 ( for that I used -resize 1260x1260). also used -profile for converting CMYK to RGB.

My input image has a white background . and i want to convert the background to transparent, which is not happening :(

can you please give me a script which can perform all the above i.e , cmyk to rgb, dpi 300, size 1260x1260, transparent background
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert the background of an image to transparent

Post by fmw42 »

Try using the proper IM syntax:

Code: Select all

convert yourimage[0]  -profile <path>\CoatedFOGRA27.icc -profile <path>\sRGB_v4_ICC_preference.icc -fuzz 10% -transparent white -resize 1260x1260 -density 300x300 -quality 80 outputimage
If that does not work, then please provide an example input image.

If the output is JPG, note that JPG does not support transparency. If the output is PNG, then -quality means something different and its values are not simply 0-100. See http://www.imagemagick.org/script/comma ... hp#quality

I have a feeling that your input may be either PSD or TIFF. It would be best to provide an example image.
laxmi131
Posts: 9
Joined: 2017-04-05T07:01:17-07:00
Authentication code: 1151

Re: Convert the background of an image to transparent

Post by laxmi131 »

Hi I tried the IM syntax which you mentioned. but that did not work.
I see that I don't have an option to attach my input file , please let me know the option where I can attach my input an output image
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert the background of an image to transparent

Post by snibgo »

You can upload to somewhere like dropbox.com and paste URLs here.
snibgo's IM pages: im.snibgo.com
laxmi131
Posts: 9
Joined: 2017-04-05T07:01:17-07:00
Authentication code: 1151

Re: Convert the background of an image to transparent

Post by laxmi131 »

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

Re: Convert the background of an image to transparent

Post by snibgo »

The image has an embedded profile, so we don't need your first CMYK profile.

Code: Select all

convert input.eps -profile sRGB.icc -transparent White -resize 1260x1260 -density 300 -units PixelsPerInch -depth 8 x.png
This works fine for me, IM v6.9.5-3.
snibgo's IM pages: im.snibgo.com
laxmi131
Posts: 9
Joined: 2017-04-05T07:01:17-07:00
Authentication code: 1151

Re: Convert the background of an image to transparent

Post by laxmi131 »

Hi,
the script worked but the backgroung which is am looking is for transparent and grid. not sure how it can be done ,
sorry for the trouble I am new to image magick.

input -- https://www.dropbox.com/s/9fx0dxt2mpae6 ... t.eps?dl=0

my output should look like the below specified in the ink
https://www.dropbox.com/s/0xpfr785cirzz ... 2.png?dl=0

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

Re: Convert the background of an image to transparent

Post by snibgo »

I'm confused. Do you want a transparent background? Does my command give you a transparent background?
snibgo's IM pages: im.snibgo.com
Post Reply