1601 posts Building the Web.
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Exclusive Author
  • Author had a File in an Envato Bundle
  • Most Wanted Bounty Winner
  • Bought between 50 and 99 items
  • Has been a member for 4-5 years
+2 more
ZoomIt says

Is it safe to use GD Library in themes ? Do any hosts have it disabled ?

I want to write my own image resizing class basically because TimThumb has no easy way to allow absolute urls ( from I find ) .

I will of course lock resizing only on the theme’s domain. Are there any other security stuff I should do ?

213 posts
  • Has been a member for 5-6 years
  • Bought between 50 and 99 items
  • Referred between 1 and 9 users
  • Exclusive Author
agusmu says

Wordpress built-in image_resize function does use GD Library, CMIIW

When GD Library is disabled, you still can upload image via Wordpress Media Library, but the additional images (thumbnail, medium, etc) will not be generated…

you can check this vt_resize function to resize images dynamically using wp built in functions… ;)

https://gist.github.com/930234
1601 posts Building the Web.
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Exclusive Author
  • Author had a File in an Envato Bundle
  • Most Wanted Bounty Winner
  • Bought between 50 and 99 items
  • Has been a member for 4-5 years
+2 more
ZoomIt says
agusmu said
https://gist.github.com/930234

Thanks, will do!

Now playing with the GD Library. Having some troubles resizing transparent PNGs :impatient:

213 posts
  • Has been a member for 5-6 years
  • Bought between 50 and 99 items
  • Referred between 1 and 9 users
  • Exclusive Author
agusmu says
2024 posts
  • Elite Author
  • Author had a Free File of the Month
  • Has been a member for 4-5 years
  • Austria
  • Exclusive Author
  • Interviewed on the Envato Notes blog
  • Envato Studio (Microlancer) Beta Tester
+3 more
revaxarts says
ZoomIt said
agusmu said
https://gist.github.com/930234

Thanks, will do!

Now playing with the GD Library. Having some troubles resizing transparent PNGs :impatient:

Transparent images do always make trouble with GD. There are some workarounds out there. Search Google!

I love Imagemagik much more but it’s not available on every server though

1601 posts Building the Web.
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Exclusive Author
  • Author had a File in an Envato Bundle
  • Most Wanted Bounty Winner
  • Bought between 50 and 99 items
  • Has been a member for 4-5 years
+2 more
ZoomIt says

Thanks guys, it was a bit tricky, but here is my solution

$image_p = imagecreatetruecolor($new_width, $new_height);
$black = imagecolorallocate($image_p, 0, 0, 0);

if($ext=='.jpg')
$source = imagecreatefromjpeg($filename);
if($ext=='.gif')
$source = imagecreatefromgif($filename);
if($ext=='.png'){
$source = imagecreatefrompng($filename);
}

$dest = imagecreatetruecolor($new_width, $new_height);
if($ext=='.png' || $ext=='.gif'){
$transparent = imagecolorallocate($dest,255,255,255);
imagecolortransparent($dest,$transparent);
imagefilledrectangle($dest,0,0,$new_width,$new_height,$transparent);
}

imagecopyresampled($dest, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

if($ext=='.png' || $ext=='.gif'){
    imagepng($dest);
}else{
    imagejpeg($dest);
}

I think pure white will go transparent because of this lol, but it’s the best solution I could compromise with.

Also resizing really seems CPU intensive even on localhost with quad core. Would not want it enabled on my live server..

by
by
by
by
by
by