hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Hosting Software and Control Panels : GD resize transparent GIF question
Reply

Hosting Software and Control Panels Software used in the web hosting industry. Topics include control panels, add-on software, setup scripts, etc.
Forum Jump

GD resize transparent GIF question

Reply Post New Thread In Hosting Software and Control Panels Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 04-12-2006, 09:01 PM
Wojtek Wojtek is offline
Aspiring Evangelist
 
Join Date: Sep 2003
Location: Montreal, Canada
Posts: 373

GD resize transparent GIF question


Hello there,

I have a slight problem.
I'm using GD to resize some transparent gifs. And the way it displays the transparancy is bugging me.

Instead of beeing transparent, it displays the black transparancy color.

Is there a way to make it display a white background whenever there is transparancy? Instead of black?

Here is the code:

PHP Code:
<?php

$image 
$_GET['i'];
$max_width $_GET['w'];
$max_height $_GET['h'];

$picture_location $image;

$picture_save str_replace($image, array(".jpg"".gif"".png"), ".temp");

$im_size GetImageSize $picture_location);
$imageWidth $im_size[0];
$imageHeight $im_size[1];

if (
eregi('.jpg'$picture_location)) { //If file is a JPG
  
$im2 ImageCreateFromJPEG($picture_location);
} elseif (
eregi('.gif'$picture_location)) { //If file is a GIF
  
$im2 ImageCreateFromGIF($picture_location);
} elseif (
eregi('.png'$picture_location)) { //If file is a PNG
  
$im2 ImageCreateFromPNG($picture_location);
}

$x_ratio $max_width $imageWidth;
$y_ratio $max_height $imageHeight;

if ( (
$imageWidth <= $max_width) || ($imageHeight <= $max_height) ) {
  
$tn_width $imageWidth;
  
$tn_height $imageWeight;
}

if ((
$x_ratio $imageHeight) < $max_height) {
  
$tn_height ceil($x_ratio $imageHeight);
  
$tn_width $max_width;
}
else {
  
$tn_width ceil($y_ratio $imageWidth);
  
$tn_height $max_height;
}

$im imageCreateTrueColor$tn_width$tn_height );

ImageCopyResampled ($im,$im20000$tn_width$tn_height,$imageWidth$imageHeight);
if (
eregi('.jpg'$picture_location)) { //If file is a JPG
  
Header("Content-type: image/jpeg");
  
Imagejpeg($im,'',100); //to print to screen
  
Imagejpeg($im,$picture_save,100);
} elseif (
eregi('.gif'$picture_location)) { //If file is a GIF
  
Header("Contrnt-type: image/gif");
  
Imagegif($im,'',100);
  
Imagegif($im,$picture_save,100);
} elseif (
eregi('.png'$picture_location)) { //If file is a PNG
  
Header("Content-type: image/png");
  
Imagepng($im,'',100);
  
Imagepng($im,$picture_save,100);
}


ImageDestroy($im);
ImageDestroy ($im2);

?>
Thank You

Reply With Quote


Sponsored Links
  #2  
Old 04-12-2006, 09:02 PM
Wojtek Wojtek is offline
Aspiring Evangelist
 
Join Date: Sep 2003
Location: Montreal, Canada
Posts: 373
Ops, wrong forum... Can mod move pelase.

Reply With Quote
  #3  
Old 04-12-2006, 10:50 PM
foobic foobic is offline
Community Liaison 2.0
 
Join Date: Feb 2005
Location: Australia
Posts: 5,112
Black is the default background colour for truecolour images. Try using imagefill to fill the new image with white before copyresampled.

Reply With Quote
Sponsored Links
  #4  
Old 04-12-2006, 11:32 PM
Wojtek Wojtek is offline
Aspiring Evangelist
 
Join Date: Sep 2003
Location: Montreal, Canada
Posts: 373
2 lines of code was all that it took
Thanks alot foobic

Problem: Solved

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
Web Host ScaleMatrix Launches Transparent Pricing Tool for Private Cloud Web Hosting News 2012-06-21 12:02:33
WHD 2012 -- How Web Hosts Can Use Migration Services to Win Customers Web Hosting News 2012-03-22 11:57:18
Beyond SOPA / PIPA at SXSW Blog 2012-03-16 15:34:26
Rackspace Blog Looks at Easy Outsourcing for App Development Blog 2012-03-05 19:07:48
Web Host Liquid Web Launches New Account Management Interface Web Hosting News 2011-09-30 19:52:50


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?