Page 1 of 2

Convert Transparent TIF to Transparent PNG

Posted: 2014-03-11T11:22:26-07:00
by annieidson
Hello All,
We're trying to use ImageMagick to process layered Adobe RGB (1998) tif format files that have transparent areas surrounding and sometimes inside the active image area to Adobe RGB (1998) png format files while retaining the natural transparency of the tif file. The layered tifs are completely inconsistent when it comes to number of layers, alpha masks and paths, but they always have transparency around the active image area. Here are a couple of examples of what I see when I look at these files in PhotoShop CS6:

Image

Image

This is the code that our system developer started with:
convert $file -alpha off -flatten -quiet -format png /Volumes/RemoteFS/Test_Output/${file%.tif}.png
But this did not uniformly retain the tif transparency in our test of roughly 1600 files. The shoe bottom png was completely opaque and the void area in the hat was also opaque:

Image

We tried to use clipping paths to isolate the transparency, but this will not work in all instances. Some images have a range of transparent pixels of anywhere from 0 to 99, so we just need to retain the native transparency found in the source tif file.

Can anyone point us in the right direction?

Thank you,

Ann

Re: Convert Transparent TIF to Transparent PNG

Posted: 2014-03-11T11:47:47-07:00
by fmw42
Post a link to your input image (not a screen snap) so others can inspect it and see what might be the issue. Note that IM does not read all the miscellaneous layers in PSD or Tiff, just the basic image layers and can only handle one kind of transparency (background most likely and not alpha channels)

Re: Convert Transparent TIF to Transparent PNG

Posted: 2014-03-11T12:40:39-07:00
by annieidson
Thanks fmw42,

I've uploaded:
http://i39.photobucket.com/albums/e161/ ... 50ce87.jpg
http://i39.photobucket.com/albums/e161/ ... 014dbb.jpg
to Photobucket but it's knocked them both down to jpgs with no alpha masks, just color masks, no paths, no layers and no transparency.

Not sure this is good enough, but am having difficulty finding free hosting for tif format files.

Re: Convert Transparent TIF to Transparent PNG

Posted: 2014-03-11T13:01:49-07:00
by fmw42
annieidson wrote:Thanks fmw42,

I've uploaded:
http://i39.photobucket.com/albums/e161/ ... 50ce87.jpg
http://i39.photobucket.com/albums/e161/ ... 014dbb.jpg
to Photobucket but it's knocked them both down to jpgs with no alpha masks, just color masks, no paths, no layers and no transparency.

Not sure this is good enough, but am having difficulty finding free hosting for tif format files.
We need your original tiff to see what is going on. Try dropbox.com (public folder).

Also please always provide your version of IM and platform when asking questions. It could be you just need to upgrade to a newer version of IM.

convert -version

will identify your version

Also what version of libtiff and libpng are you using? Those delegates may be the issue also.

You can get those from

convert -list format

Re: Convert Transparent TIF to Transparent PNG

Posted: 2014-03-11T13:07:00-07:00
by annieidson

Re: Convert Transparent TIF to Transparent PNG

Posted: 2014-03-11T13:09:43-07:00
by fmw42
Please answer the questions above about your IM version, platform, versions of libtiff and libpng

Re: Convert Transparent TIF to Transparent PNG

Posted: 2014-03-11T13:23:41-07:00
by fmw42
I have tested your shoe.tiff and find that it does not extract the transparency even with -define tiff:alpha=unassociated. So I will pass this on to one of the IM developers to examine further. Your other image, may have too complex a layer structure to get something meaningful, but I will leave that to the IM developers. I tested with IM 6.8.8.8 beta, LIBTIFF, Version 4.0.3, libpng 1.5.17

Code: Select all

im6888beta convert shoe.tif shoe.png

im6888beta convert shoe.tif -define tiff:alpha=unassociated shoe.png
Neither successfully extracted the transparency.

Re: Convert Transparent TIF to Transparent PNG

Posted: 2014-03-11T13:38:44-07:00
by annieidson
Our system developer is using the following version on Red Hat Enterprise Linux Server release 6.5:
Version: ImageMagick 6.5.4-7 2012-04-10 Q16 OpenMP http://www.imagemagick.org

Am checking now about libtiff and libpng versions.

Re: Convert Transparent TIF to Transparent PNG

Posted: 2014-03-11T13:40:45-07:00
by fmw42
6.5.4-7 is very old (340 versions old). You may have to upgrade, once the issue is resolved. For me it did not work in IM 6.8.8.8 beta.

Re: Convert Transparent TIF to Transparent PNG

Posted: 2014-03-11T14:00:26-07:00
by annieidson
Hello fmw42,

This from our system developer:
libtiff: 3.9.4
libpng: 1.2.48,1.2.49

Re: Convert Transparent TIF to Transparent PNG

Posted: 2014-03-11T14:28:45-07:00
by snibgo
The shoe is easy (IM v6.8.8-7 on Windows 8.1):

Code: Select all

convert shoe.tif -clip -alpha transparent +clip -channel A -negate s.png
The hat isn't so easy:

Code: Select all

convert hat.tif -clip -alpha transparent +clip -channel A -negate h.png
Possibly the clipping path is defined in some strange way, or IM processes it differently to PS.

Re: Convert Transparent TIF to Transparent PNG

Posted: 2014-03-11T15:01:00-07:00
by fmw42
snibgo wrote:The shoe is easy (IM v6.8.8-7 on Windows 8.1):

Code: Select all

convert shoe.tif -clip -alpha transparent +clip -channel A -negate s.png
The hat isn't so easy:

Code: Select all

convert hat.tif -clip -alpha transparent +clip -channel A -negate h.png
Possibly the clipping path is defined in some strange way, or IM processes it differently to PS.
Yes, I forgot about clip paths. This seems to work to get the outside area. I suspect the inside area is due to the path not reversing direction as snibgo has mentioned in another post. see viewtopic.php?f=1&t=25154

However, I did get warning messages. Note that IM does not handle group layers.

On second review, the below code changes the clipped area around the brim to black rather than snibgo's white or proper transparency. So it is no better than snibgo's version or possibly worse.

Code: Select all

convert hat.tif -background none -flatten -clip -alpha transparent +clip -channel A -negate h.png
These seem to be just warnings about unknown meta tag fields and probably can be ignored.

Code: Select all

convert: Incompatible type for "RichTIFFIPTC"; tag ignored. `TIFFFetchNormalTag' @ warning/tiff.c/TIFFWarnings/850.
convert: Unknown field with tag 282 (0x11a) encountered. `TIFFReadCustomDirectory' @ warning/tiff.c/TIFFWarnings/850.
convert: Unknown field with tag 283 (0x11b) encountered. `TIFFReadCustomDirectory' @ warning/tiff.c/TIFFWarnings/850.
convert: Unknown field with tag 296 (0x128) encountered. `TIFFReadCustomDirectory' @ warning/tiff.c/TIFFWarnings/850.
convert: Unknown field with tag 306 (0x132) encountered. `TIFFReadCustomDirectory' @ warning/tiff.c/TIFFWarnings/850.
convert: Incompatible type for "FileSource"; tag ignored. `TIFFFetchNormalTag' @ warning/tiff.c/TIFFWarnings/850.
convert: Incompatible type for "SceneType"; tag ignored. `TIFFFetchNormalTag' @ warning/tiff.c/TIFFWarnings/850.
convert: Incompatible type for "RichTIFFIPTC"; tag ignored. `TIFFFetchNormalTag' @ warning/tiff.c/TIFFWarnings/850.
Looking more carefully in PS, your hat.tif image has many alpha channels in addition to a clip path. IM cannot handle more than one alpha channel and perhaps not even that if there is background transparency (to my knowledge).

Re: Convert Transparent TIF to Transparent PNG

Posted: 2014-03-18T09:32:34-07:00
by annieidson
Hello All,
Sorry, was out of town at the end of last week and was unable to respond and clearly needed to do more research about transparency channels.

I also think I need to give you all a more clear idea of our needs and perhaps should have started there.

I work at a retail marketing photo studio where we make images of everything and anything, apparel, lawn mowers, fertilizer, water bottles, purses, garden hose, shoes, accessories, baby carriages, cosmetics, jewelry, basically if you can buy it at a store, we shoot it. Once the image has been captured on the Photo floor, it will go through digital retouching where basic cleanup and compositing of multiple captures is performed, where applicable, a clipping path is generated around the merchandise using a variety of selection methods, and the background is knocked out, leaving a transparent frame around the merchandise, or merchandise and model, as the case may be. Sometimes an image will go through multiple rounds of retouching until it is approved. This means that there will be unpredictable names and numbers of layers, alpha channels and clipping paths in any given file.

Most of our final deliverables are pngs with transparent backgrounds, with the occasional jpg and flattened tif thrown in.

Based on last year's volume, we expect to process 125,000 images over the next year for this pilot account alone, more, if this works out and we can use ImageMagick for other efforts. That works out to an average of 479/work day, but in practice, it's more like 100/work day in the slower seasons and 1,000 or more during our peak crunch times. We're currently processing these with a Photoshop batch automation, which ties up a lot of machines and produces apple double files on our afp servers.

Here are the specifications for our png deliverables:
Color Profile: Adobe RGB (1998) (8bpc) - this value is inherent in the parent tif document
Resolution: 300ppi - this value is inherent in the parent tif document
Retain Transparency inherent in the parent tif document
No interlacing
File compression, I have only two options for file compression through a Photoshop "Save As" command, "None" and "Smallest/Slow", we use "Smallest/Slow"

We can't use clipping paths to define the transparent areas. A clipping path is a vector graphic and will not support any partial transparency that may occur in images where there are soft edges, such as a model's hair or fur trim on a coat, just to name a couple examples. I've uploaded an example of this type of file for reference here:
https://www.dropbox.com/s/vbhbeanjp7kqmky/FuzzyCoat.tif
Complete with all it's layers, paths, and channels.

As you can see in FuzzyCoat.tif the clipping path around the fur trim is very loose, the final transparency around the fur was probably generated with a soft "Eraser" tool, a "Color Range" selection, a "Quick Selection" tool or any other Photoshop tool at the disposal of our retouching staff. This is not predictable, it depends on the individual retoucher's choice to get the job done in the time allotted. If we use the clipping path to define transparency using FuzzyCoat.tif as an example, we'll end up with a big white halo - and not the pretty kind - around the hood.

The other problem with using the clipping path is the fact that it is set before the image is reviewed. It's entirely possible that an edit will be requested that will change the overall outside shape and the clipping path will not be corrected. We'll just make the edit and not revisit the clipping path - it's only used in the initial round of retouching to knock out the background.

Nor is it practical to try to make our clipping paths clockwise and counter clockwise - again, some images will be pathed with the "Pen" tool, where that could work, but if the retoucher chooses to use other methods to save time, such as the "Quick Selection" tool or a "Color Range" selection, that goes out the window.

I'm not sure the warning message "IM does not handle group layers" will present a problem, if I'm understanding it correctly. Does this refer to layer groups where several layers are grouped in the layer palette in a folder or does it just mean multiple layers? Regardless, most of these images have complex layer structures like hat.tif, but usually all layers but the current image layer are turned off or are obscured by the current image layer.

What kind of befuddles me is that this is such an easy Photoshop command to implement, so it would seem like it would be fairly straightforward in ImageMagick as well.

Hope this helps,

Ann

Re: Convert Transparent TIF to Transparent PNG

Posted: 2014-03-18T10:29:22-07:00
by fmw42
As I understand it, IM does not know about group layer - groups of layers. It can handle multiple layers, but not in groups. The other current limitation is that IM can handle only one alpha channel, but this may not be extracted if the image has background transparency also. I think a switch was recently introduced in IM to handle this for tiff.

If you are using the alpha channels in your image and there are more than one, then you could post to the Developes forum and see if they are willing to add a new define or argument to extract one or more of the different alpha channels.

As I understand your example images, they were using clip paths. But in IM nested clip paths - one inside another - need to have the path defined in opposite directions.

I do not know what to tell you. If you do not want to use clip paths, then post another example that does not so we can see what issues arise with that image.

Re: Convert Transparent TIF to Transparent PNG

Posted: 2014-03-18T11:00:09-07:00
by snibgo
Another avenue you might want to explore: I sometimes use Gimp for multiple layers, interactive editing, etc, saving the result in the native file format, XCF. ImageMagick can read these files but sometimes gets it wrong and ignores Gimp's metadata. So I write scripts (in Gimp's Python language) to push data out from Gimp. I can run these from the command line or within other scripts.

For me, this is the better approach. Instead of using IM to pull data out of Gimp files, I use Gimp to push data out of its own files. This avoids all problems of IM not fully understanding Gimp.

A quick web search suggests that this is also possible with Photoshop, eg http://ps-scripts.com/bb/viewtopic.php?t=515