example .jpg:

enter image description here

Ideal .png result:

enter image description here


Command line is quicker. Install Imagemagick.

One file:

convert -transparent white whatever.jpg whatever.png

More files:

Put together a bash script file:

for img in *.jpg; do
convert -transparent white "$filename.jpg" "$filename.png"

Run it and then you will be done. Note that the above will add transparency to everything that is white 'FFFFFF' including any pixels of that colour inside your image. "topLeftPixel" can be used instead of "white" for autodecting background colour.

If the white pixels in image problem is a problem then you can do Photoshop batch. Layer mask is better than 'delete'-clearing the white pixels as you do not actually alter the RGB layers.

| improve this answer | |
  • 1
    I'm not familiar with Imagemagick, but if that only converts pure #FFFFFF pixels, won't it leave ugly JPEG artifacts? For instance, converting all white pixels to black in the reference JPG results in i.stack.imgur.com/CvvDy.png – Farray May 31 '11 at 16:10
  • 1
    You can add fuzzy in there if you want - there is an option in the ImageMagick manual. Sometimes some artwork is 'mounted' on white and you might be using against a white page background so 'fuzzy' may not matter. – Theodore May 31 '11 at 16:19

If you use GIMP, I can suggest this tutorial: Perfect masking using a highpass guide. I had very good results with complex images by following it.

| improve this answer | |

It depends on the software you have available to you.

If you have Photoshop, for an image that clean you can do it very quickly:

  1. Open the file.
  2. Double-click the Background layer to convert it to a normal layer.
  3. Use Magic Wand (w) (low Tolerance and Contiguous and Anti-alias checked) to select the white background.
  4. Press Delete key to clear the selection.
  5. Save as a PNG or Save-for-web as PNG.

If you get a white halo around your image, try using menu SelectModifyExpand (with 1-2px setting) after step 3.

| improve this answer | |
  • 1
    I think you can do better with a layer mask. – Theodore May 31 '11 at 9:50
  • @Theodore If just resaving as a PNG, what is the benefit of preserving the underlying RGB info with alpha channel instead of just clearing pixels? – Farray May 31 '11 at 14:45
  • 1
    It is about using the rgb layers for the image and the alpha channel for transparency. If you delete pixels you do not get as good an edge as if you use a layer mask. Maybe that is just the way I hit the delete key. Give it a go, I promise you will get better results. That select-modify-expand is also verging on the morally wrong, you'll never get 'fine hair detail' doing it like that, but you will with layer mask. – Theodore May 31 '11 at 14:55
  • @Theodore - There is no reason you can't have as fine of a line using "clear selection" as you can with a mask. "Clear Selection" only removes pixel data for fully-transparent pixels. For anti-aliased pixels it stores RGB data with alpha and you can still have a clean edge. In this comparison, I do not believe there is a substantial difference between the masked & cleared images. As for recommending "Select-Modify-Expand", the question asked for "easiest way". Easiest rarely equals best. – Farray May 31 '11 at 16:06
  • 1
    You can always delete a layer mask and apply it if you really want the empty pixel look with no extra layer/channel. You can also blur it and all kinds of things to get the exact results needed. If you have just deleted the pixels, albeit 'feathered' as per your technique you have lost the ability to re-work an edge later on. – Theodore May 31 '11 at 16:27

For the sake of completion i had to add one more method (if you using photoshop). As your image is not complex you can use the magic wand, or select color. But best method for separating a complex foreground from a relatively less complex background is Channel masking.

Here is a good tutorial which might be helpful for future visitors: http://graphics.tutremix.com/tutorials/photo-effect/how-to-make-a-lightning-man-photomanipulation-in-photoshop-day-1/

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.