Page 1 of 1
-transparent-color query
Posted: 2014-11-06T01:04:47-07:00
by Bonzo
I am creating an image with some resizes, composites and rotates and saving as a png with a transparent background and all is going well.
This code is going onto a website for users to upload their own images and I am thinking there is bound to be a problem as some of the users will download the new image and save as a jpg at some point and so I want to set the transparent colour to white instead of the default black.
Simple I thought just add a -transparent-color white but it does not seem to work no matter where or how many times I put it into the code.
My actual code is quite complicated and has a lot of variables in and so is difficault to post here - what is the proper usage of -transparent-color?
It is a bit hard writing some test code when nothing happens as expected.
Re: -transparent-color query
Posted: 2014-11-06T02:39:46-07:00
by snibgo
I think (but could be wrong) that "-transparent-color" applies only to paletted images. JPEG files are never paletted.
Re: -transparent-color query
Posted: 2014-11-06T15:03:46-07:00
by Bonzo
Thanks for the reply; I was hoping to find a way to specify the colour jpg would use to replace transparency.
Re: -transparent-color query
Posted: 2014-11-06T19:45:17-07:00
by snibgo
I think the conversion to jpg simply removes the alpha channel, so the colour will be the underlying colour of those pixels. "-background XX -alpha background" will turn fully transparent pixels into transparent-XX, where XX is any colour.
Re: -transparent-color query
Posted: 2014-11-10T11:08:43-07:00
by Bonzo
Thanks snibgo but that did not seem to have any effect - I suppose it depends where it is in the options list?
This has brought up another problem; when looking at my produced image in photoshop the image is not fixed onto the background.
Code: Select all
convert image1.png image2.png -gravity center -geometry -5-106 -composite output.png
The image2 is fixed to the image1 correctly but the combined image 1&2 is not fixed to the transparent background; I would say I have two layers.
Using -flatten turns my transparency black on my combined image 1&2 but it is still not fixing my combined image 1&2 to the transparent background.
Does this matter? I would not think so but I would like to fix it if I could.
Re: -transparent-color query
Posted: 2014-11-10T11:55:03-07:00
by snibgo
Code: Select all
convert -size 200x200 gradient:red-blue -alpha transparent t.png
convert t.png t1.jpg
convert t.png -background Green -alpha background t2.jpg
t.png has 4 channels. The colour channels have values from red to blue, but the alpha channel is fully transparent.
t1.jpg strips out the alpha channel, so it shows pixels that vary from red to blue.
The third command changes all of the fully-transparent pixels, making them transparent-green. Saving it as jpg removes the alpha channel, so the result is green.
I don't understand "the combined image 1&2 is not fixed to the transparent background".
Re: -transparent-color query
Posted: 2014-11-10T14:14:47-07:00
by Bonzo
Right I get :
t.png completely transparent
t1.jpg Red to blue gradient
t2.jp completely green
Which is as expected; thanks for the examples. I will have another play with my code later and see what I get.
This image was created with the code I posted above and if you open it in photoshop and probably Gimp you will see that the easel ( image1.png )and the picture ( image2.png ) are combined but they are floating over a transparent background. Not anchored or merged?
In photoshop if I "deselect layers" they are fixed as one image. Sorry to keep using Photoshop but that is all I currently have installed.
http://www.rubble.info/donotdelete/1_1415653499_CVH.png
Re: -transparent-color query
Posted: 2014-11-10T15:01:46-07:00
by snibgo
The image looks normal to me in Gimp. The image is 200x384 pixels, but "identify -verbose" shows fields:
Code: Select all
Thumb::Image::Height: 1564
Thumb::Image::Width: 815
Perhaps Photoshop interprets this as a canvas larger than the image.
Re: -transparent-color query
Posted: 2014-11-10T15:06:58-07:00
by Bonzo
Good point - the image is bounded by a "box" and that is smaller than the "canvas". If I drag the image around it disappears off the edge of the canvas and where ever I deselect the layers the image stays. I had assumed it was a general image problem, but it could just be something photoshop does or interoperates from the image data. I will not worry about it; thanks again for the help.
Re: -transparent-color query
Posted: 2014-11-11T12:18:59-07:00
by Bonzo
I had a brainwave this morning about the canvas anomaly; my version of Photoshop has an option to delete pixels after cropping or retain. I have my option set to retain and I assume that was causing that error.