Transparent background in JPEG image
Asked Answered
S

7

61

How can I set a transparent background on JPEG image? This is a doubt of many colleagues of mine.

What would be the solution using Paint on Windows?

What are the other simple alternatives?

Snail answered 3/6, 2013 at 21:28 Comment(1)
People interested in web design should read this answer for workarounds.Lyophilize
J
85

You can't make a JPEG image transparent. You should use a format that allows transparency, like GIF or PNG.

Paint will open these files, but AFAIK it'll erase transparency if you edit the file. Use some other application like Paint.NET (it's free).

Edit: since other people have mentioned it: you can convert JPEG images into PNG, in any editor that's capable of working with both types.

Jaunitajaunt answered 3/6, 2013 at 21:31 Comment(9)
This comment is for anyone with the same doubt: Yes. I just installed Paint.NET and it's really very simple... You just need to open the image, select white area with the magic wand and delete it.Snail
Careful with that, though. Depending on the sensitivity of the wand, and the color gradient, you might still get an "aura", or lots of small squares, both the color of the original background. This will be more noticeable if the image is set against a background that's the opposite color of its original one. It takes only a wand selection and a deletion to make things transparent, but it takes some hand work to make stuff look nice.Jaunitajaunt
Don't tell like this… I just added a transparent channel to a test image, wrote a word with an eraser in GIMP, next saved it in «.jpg». When I opened it again with GIMP, I indeed didn't saw the word. It seemed that you were right… But know what? I found that the image still hold the transparent channel! Next I choose the tool «filling», and pressed with this somewhere in the area with my transparent word — and it did appeared!Kennethkennett
arms -- what do you mean by 'delete it'? Delete what? Where is there a 'delete'? Please clarify.Galop
@Galop I believe he means deleting the selected area, after you have made a selection with the magical wand tool. OP's goal was to turn some piece of white background into transparent background.Jaunitajaunt
Thank you Renan. But I was trying to determine if the comment meant there was a delete tab, delete in a dropdown, delete when doing a right-click, etc. Turns out I tried using the Delete button and that did the trick.Galop
This is all crap. The tool, PAINT.NET or whatever is completely irrelevant. You aren't working with a "jpeg" when you edit an image using a tool. It's just image data. The file format itself doesn't support transparency. As for colored halos when deleting areas - that's what fuzzy selection is all about. Not a problem. Lots of tools can do the work (but not Windows Paint), but the work is undone if you save as a JPEG. See my answer below if you want a partial solution.Eastbourne
@MysteryPancake JPEG 2000 is not JPEG.Jaunitajaunt
GIMP could work tooBrinn
L
41

If you’re concerned about the file size of a PNG, you can use an SVG mask to create a transparent JPEG. Here is an example I put together.

Lemke answered 8/9, 2014 at 17:9 Comment(2)
I can't believe I only saw this now. Awesome answer.Jaunitajaunt
And here is another SVG example using clipPath (some comments therein may be useful).Lyophilize
D
20

JPEG can't support transparency because it uses RGB color space. If you want transparency use a format that supports alpha values. Example PNG is an image format that uses RGBA color space where (r = red, g = green, b = blue, a = alpha value). Alpha value is used as an opacity measure, 0% is fully transparent and 100% is completely opaque. pixel.

Displeasure answered 3/6, 2013 at 21:47 Comment(0)
P
11

JPG does not support a transparent background, you can easily convert it to a PNG which does support a transparent background by opening it in near any photo editor and save it as a.PNG

Premundane answered 3/6, 2013 at 21:45 Comment(0)
V
8

How can I set a transparent background on JPEG image?

If you intend to keep the image as a JPEG then you can't. As others have suggested, convert it to PNG and add an alpha channel.

Vantage answered 3/6, 2013 at 22:19 Comment(0)
E
6

Just wanted to add that GIF "transparency" is more like missing pixels. If you use GIF then you will see jagged edges where the background and the rest of the image meet. Using PNG, you can smoothly "composite" images together, which is what you really want. Plus PNG supports highly quality images.

Don't use "Paint". There are many high quality art applications for doing art work. I think even the cell phone apps (Pixlr is pretty good and free!) and web-based image editting apps are better. I use Gimp - free for all platforms.

While a JPEG can't be made transparent in and of itself, if your goal is to reduce the size of very large image areas for the web that need to contain transparent image areas, then there is a solution. It's a bit too complicated to post details, but Google it. Basically, you create your image with transparency and then split out the alpha channel (Gimp can do this easily) as a simple 8-bit greyscale PNG. Then you export the color data as a JPG. Now your web page uses a CANVAS tag to load the JPG as image data and applies the 8-bit greyscale PNG as the Canvas's alpha channel. The browser's Canvas does the work of making the image transparent. The JPEG stores the color info (better compressed than PNG) and the PNG is reduced to 8-bit alpha so its considerably smaller. I've saved a few hundred K per image using this technique. A few people have proposed file formats that embed PNG transparency info into a JPEG's extended information fields, but these proposal's don't have wide support as of yet.

Eastbourne answered 23/7, 2015 at 18:32 Comment(0)
H
5

JPG doesn't support transparency

Hornbeck answered 3/6, 2013 at 21:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.