Thumbnails using images with transparency

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?".
rpalmer
Posts: 9
Joined: 2014-01-30T03:58:47-07:00
Authentication code: 6789

Thumbnails using images with transparency

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Thumbnails using images with transparency

Post by snibgo »

Sure. For example:

Code: Select all

convert -size 300x100 -background none label:snibgo pattern:checkerboard +swap -composite c.png
snibgo's IM pages: im.snibgo.com
rpalmer
Posts: 9
Joined: 2014-01-30T03:58:47-07:00
Authentication code: 6789

Re: Thumbnails using images with transparency

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Thumbnails using images with transparency

Post 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.
snibgo's IM pages: im.snibgo.com
rpalmer
Posts: 9
Joined: 2014-01-30T03:58:47-07:00
Authentication code: 6789

Re: Thumbnails using images with transparency

Post 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)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Thumbnails using images with transparency

Post 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?
snibgo's IM pages: im.snibgo.com
rpalmer
Posts: 9
Joined: 2014-01-30T03:58:47-07:00
Authentication code: 6789

Re: Thumbnails using images with transparency

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Thumbnails using images with transparency

Post 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?
snibgo's IM pages: im.snibgo.com
rpalmer
Posts: 9
Joined: 2014-01-30T03:58:47-07:00
Authentication code: 6789

Re: Thumbnails using images with transparency

Post 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!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Thumbnails using images with transparency

Post 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.
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: Thumbnails using images with transparency

Post 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.
rpalmer
Posts: 9
Joined: 2014-01-30T03:58:47-07:00
Authentication code: 6789

Re: Thumbnails using images with transparency

Post 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!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Thumbnails using images with transparency

Post by snibgo »

If you post your eps file somewhere like dropbox.com and paste the URL here, we can experiment.
snibgo's IM pages: im.snibgo.com
rpalmer
Posts: 9
Joined: 2014-01-30T03:58:47-07:00
Authentication code: 6789

Re: Thumbnails using images with transparency

Post by rpalmer »

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

Re: Thumbnails using images with transparency

Post 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.
snibgo's IM pages: im.snibgo.com
Post Reply