Jump to content

How to convert jpeg/jpg format to png/gif transparent format


fifin04

Recommended Posts

Hi all,

 

I am currently making a website that has e-custom functions and a back end for the client.

 

I want them to be able to upload images - but they need to be transparent. I do not want to leave this in the hands of the client, so I am looking at ways of using the GD library to make the change

 

I got no issue with the png/gif type for upload/resize function since this type already transparent background but my major problems is how to deal with jpeg/jpg image type which is their background was not a transparent...so is it possible I can change/ convert to png/gif type upon successful of uploading image...so the new final image will be png/gif type with transparent background...is it doable...I am not even sure it is possible...?

 

Thanks for any help..

Link to comment
Share on other sites

I do try with this tiny script and it's do the trick the only thing is the image is still having background colour so how can I remove the background colour and make it as transparent background

 

here's the code

 


//source jpeg image with white background colour it can be any colour as I assume 
$image = ImageCreateFromJPEG("bunnyjpeg_nottransparent.jpg");


      header("Content-Type: image/png");

      ImageJpeg($image, "mynewbunnypic.png");

      ImageDestroy($image);

 

hope someone will give me some shed on light on this...

 

 

Thanks in advanced

Link to comment
Share on other sites

imagecolortransparent(): http://php.net/manual/en/function.imagecolortransparent.php

 

Do you have some logic in mind to determine "which" color should be made transparent? For example, if you decide that white should always be transparent, then that is simple enough. But,the image could have white that is part of the background and white that is part of the image itself. It would be difficult, if not impossible to programatically determine which is which and even if you could it would be difficult to make some portions of the same color transparent while making other portions not transparent.

 

For example, in this image you would want to make the outside white color transparent, but not the white which makes up "Quaker State".

QS%20Logo.jpg

 

You will also have a heck of a time dealing with the vignette

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.