473,756 Members | 5,955 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

HaLo2FrEeEk
404 Contributor
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 2054

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

Similar topics

3
2669
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: $FileDest = "/uploads/1.gif"; if (!move_uploaded_file($_FILES, $FileDest)):
5
2515
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 just be cut off, with no horizontal scrollbar. If the browser window is wider than the image, then I'd like a gray region to the right of the image. (The right side of the image fades to gray, so the image will look okay even if the browser...
3
1866
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
1454
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 thanks in advance, --prem
2
8183
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 NewFont As New Font(fg.Font.FontFamily, 10, FontStyle.Regular) Dim g As Graphics
9
2116
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;) associated with a selector, it gave me this error message: Line : 30 (Level : 1) You have no background-color with your color : #navlist li a Here's the CSS fragment that it doesn't like:
2
4523
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
3547
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 3 system, and when I tried the same procedures I get the following errors:- $ python pil_jpg.py Exception in Tkinter callback Traceback (most recent call last):
2
1806
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, similar to how Google Maps itself works, except with the design of the site on the background rather than a map of the world. I initially hired someone to do it in PHP (don't bite, please :-) but it seems that I forgot about one thing: the...
1
3298
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
10040
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9713
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7248
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5142
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3806
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3359
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2666
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.