Page 1 of 2

Thumbnails using images with transparency

Posted: 2014-01-30T04:08:41-07:00
by rpalmer
Hi,

I've been searching for a way to do the following and struggling.

I have been using convert and -thumbnail and a size for a while and all has been well. However I now need to extend this a little to cope with images that have transparency, I've set the Alpha layer to white or black but then found that depending on the content of the image this looks awful. I don't know ahead of time which colour to use.

Is there a way I can use convert to replace the transparent Alpha layer with the built in checkerboard, which is universally seen as transparent, and resize down with the -thumbnail to a jpg.

Just to make this more fun I need this in one execution and able to run on PC or Mac from a command line.

Many thanks

Re: Thumbnails using images with transparency

Posted: 2014-01-30T04:36:24-07:00
by snibgo
Sure. For example:

Code: Select all

convert -size 300x100 -background none label:snibgo pattern:checkerboard +swap -composite c.png

Re: Thumbnails using images with transparency

Posted: 2014-01-30T04:46:54-07:00
by rpalmer
Hi,

Thanks for your reply, it didn't work though, here are my results.

Code: Select all

convert -size 300x100 -background none label:snibgo pattern:checkerboard +swap -composite in.eps
- replaced transparent backgraound with the checkerboard and the text "snibgo"

I also tried outputting to a file to see if that helped

Code: Select all

convert -size 300x100 -background none label:snibgo pattern:checkerboard +swap -composite in.eps out.jpg
- it created 2 files

1) out-0.jpg, with the background and the text "snibgo"
2) out-1.jpg, copy of in.eps but with white background

Thanks

Re: Thumbnails using images with transparency

Posted: 2014-01-30T05:23:12-07:00
by snibgo
"-size 300x100 -background none label:snibgo" is just an example image. Replace it with your own image, so you might have:

Code: Select all

convert in.png pattern:checkerboard +swap -composite out.png
This should replace transparency with checkerboard, which I think is what you want.

Re: Thumbnails using images with transparency

Posted: 2014-01-30T05:51:40-07:00
by rpalmer
Sorry, still no go, but what you describe what I am trying to achive is correct.

The eps file is a simple 2.5 cm square box with text written in the forground in black in 1 layer if opened in photoshop but you can pick the text up and move it around with the move tool. I don't think I can attach it to the group but here are my results again.

Code: Select all

convert in.eps pattern:checkerboard +swap -composite out.png
Black image

Code: Select all

convert in.eps pattern:checkerboard +swap -composite out.jpg
Black image

Code: Select all

convert in.eps pattern:checkerboard -composite out.png
Checkerboard in top left of image on top of everything

If it helps I am using the following and testing on PC
Imagemagick version 6.7.9-0 2012-08-14 Q16
Ghostscript version 9.06 (2012-08-08)

Re: Thumbnails using images with transparency

Posted: 2014-01-30T06:04:34-07:00
by snibgo
v6.7.9 is 3 (?) years old. I suggest you upgrade.

I know nothing about eps and don't have a viewer for them.

Does my command work for you?

Code: Select all

convert -size 300x100 -background none label:snibgo pattern:checkerboard +swap -composite c.png
You should get "snibgo" in black letters over a checker background.

Next test: what does ...

Code: Select all

convert in.eps out.png
... give? Black text on a transparent background, or what?

Re: Thumbnails using images with transparency

Posted: 2014-01-30T06:20:45-07:00
by rpalmer

Code: Select all

convert -size 300x100 -background none label:snibgo pattern:checkerboard +swap -composite c.png
This gives me a checkerboard with "snibo" text on it

Code: Select all

convert in.eps out.png
This gives me a white backgrounded with the black text in the foreground

Re: Thumbnails using images with transparency

Posted: 2014-01-30T06:39:08-07:00
by snibgo
rpalmer wrote:This gives me a white backgrounded with the black text in the foreground
So they don't have transparency. I'm confused. What are you trying to do?

Re: Thumbnails using images with transparency

Posted: 2014-01-30T07:11:17-07:00
by rpalmer
The plot thickens.

I opened the EPS in Photoshop, which shows it having transparency, and "saved as" a PNG. I then ran your suggested

Code: Select all

convert in.png pattern:checkerboard +swap -composite out.png
This has given me a checkerboard background but only showing me a small portion of the image so I guess a size needs to be added or a tile (I've seen somewhere).

Could it be the way the EPS is read in the first place?

Excuse the questions I am very much a novice with Imagemagick!

Re: Thumbnails using images with transparency

Posted: 2014-01-30T07:38:36-07:00
by snibgo
An EPS (Encapsulated PostScript) file may contain only vectors, so when you rasterise it (convert to pixels) you may need to say how many pixels you want. For IM, you do this with "-density 72 -units pixelsperinch" or similar, before the input image.

Re: Thumbnails using images with transparency

Posted: 2014-01-30T10:57:24-07:00
by fmw42
This works perfectly fine for me on IM 6.8.8.4 Q16 Mac OSX (Ghostscript 9.06) using IM's display to view it.

Code: Select all

convert -size 300x100 -background none label:snibgo pattern:checkerboard +swap -composite in.eps
What is your IM version, platform and ghostscript version?

convert -version

gs --version


Probably you need to upgrade GS and perhaps IM.

Re: Thumbnails using images with transparency

Posted: 2014-01-31T03:15:49-07:00
by rpalmer
Hi thanks for your help so far guys.

I've upgraded to the following versions just to make sure

convert -version
Version: ImageMagick 6.8.8-3 Q8 x64 2014-01-19

gswin64 -version
GPL Ghostscript 9.10 (2013-08-30)

Code: Select all

convert -thumbnail 80x80 -density 72 -units pixelsperinch in.eps pattern:checkerboard +swap -composite out.jpg
Still gives me a black image with small visible check line at the bottom

When I open the EPS in Photoshop it does ask me for

Width (and in what)
Height (and in what)
Resolution (and in what)
Mode (Greyscale, RGB etc)
Anti-aliased (true/false)
Constrain Proportions (true/false)

Export the imported EPS from Photoshop to a PNG with transparency, doing nothing other than opening and saving.

Code: Select all

convert -thumbnail 80x80 -density 72 -units pixelsperinch in.png pattern:checkerboard +swap -composite out.jpg
Works but only 1 checkerboard behind it while examples I've seen looked more like a chess board but guess I need another attribute to make that happen

So, changing the version has made no difference but hopefully I've given a little more insight.

Thanks for all your help, this has been driving me crazy!

Re: Thumbnails using images with transparency

Posted: 2014-01-31T03:23:35-07:00
by snibgo
If you post your eps file somewhere like dropbox.com and paste the URL here, we can experiment.

Re: Thumbnails using images with transparency

Posted: 2014-01-31T03:30:55-07:00
by rpalmer

Re: Thumbnails using images with transparency

Posted: 2014-01-31T04:43:42-07:00
by snibgo
ImageMagick can't see any transparency in in.eps.

From comments on these forums, it seems that Photoshop has two different types of transparency, and IM can see only one of them.