473,320 Members | 2,035 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to load a JPEG image and make the background transparent?

HaLo2FrEeEk
404 256MB
I've got an image that I want to load, it's a JPEG image and it has a solid background of color rgb(11, 12, 14). I want to make the background transparent and outpt the image as a PNG. I've tried this code:

Expand|Select|Wrap|Line Numbers
  1. header("Content-Type: image/png");
  2. $im = imagecreatefromjpeg("http://www.bungie.net/stats/reach/nightmap.ashx");
  3. $bg = imagecolorallocate($im, 11, 12, 14);
  4. imagesavealpha($im, true);
  5. imagecolortransparent($im, $bg);
  6. imagepng($im);
It didn't work. I thought I knew why, too. JPEG images are palette based not true color, so they can't have transparency. I tried changing my code to this:

Expand|Select|Wrap|Line Numbers
  1. header("Content-Type: image/png");
  2. $jpeg = imagecreatefromjpeg("http://www.bungie.net/stats/reach/nightmap.ashx");
  3. $im = imagecreatetruecolor(imagesx($jpeg), imagesy($jpeg));
  4. imagecopymerge($im, $jpeg, 0, 0, 0, 0, imagesx($jpeg), imagesy($jpeg), 100);
  5. imagedestroy($jpeg);
  6. $bg = imagecolorallocate($im, 11, 12, 14);
  7. imagesavealpha($im, true);
  8. imagecolortransparent($im, $bg);
  9. imagepng($im);
Creating a truecolor image and copying my JPEG image to it, then operating on the truecolor image. Still didn't work.

Anyone have any ideas as to how I might get this to work, preferably without using a mask.
Feb 9 '11 #1
0 2029

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Ming | last post by:
Hi All, I want to write a PHP webpage which allows people to upload images (no matter what formats) to me and at the same time converts any non-jpeg image to JPEG. Here's what I have: ...
5
by: Benjamin Esham | last post by:
Hello all, I have a very wide image that I want positioned in the extreme top left of the page. If the browser window is too narrow to contain the whole thing, that's fine-- the image should...
3
by: Rudy.Jean | last post by:
HI Table Background & Transparent GIF are the new trend to protect your pics. Is it efficient or can people still go around and take my pics? thanks
3
by: prem | last post by:
Hi all, I want to read the colors used in a jpeg image. I want the code or any any other code components that can do that. any suggestion , links and samples will be gratly appreciated ...
2
by: Kalvin | last post by:
I keep getting my string inside a black box with this code. I would like to make the background transparent. Any help on this will be appreciated very much. '**** BEGIN CODE **** Try Dim...
9
by: Rhino | last post by:
I've been updating some CSS today and got one odd error from the validator at http://jigsaw.w3.org/css-validator/. Every time I had 'background: transparent;' (or background-color: transparent;)...
2
by: kishkin | last post by:
Hello everybody! I just want to make window transparent. ;) At this moment I've found only ideas of taking screenshots to make background... Anything else? Thanks for help!
9
by: peter.mosley | last post by:
Hello again I'm still wrestling with Python / Tkinter / PIL. I have almost got it to work - on a Fedora Core 1 system I can now display images in a Tkinter window. But I also run a Fedora Core...
2
by: Michiel Sikma | last post by:
Hello everybody. I'm currently involved in a site building project in which we're going to use the Google Maps API. The user will be able to browse the site by looking over a really large image,...
1
by: diya khan | last post by:
hi frndz.. i wann 2 know that how can i load a JPEG image file in C.. i have loaded a 16 color bitmap file but due 2 colors prb jpeg file is not loaded..:S so plzzzz help me.. thnx in advance..
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.