1646 posts Building the Web.
  • Has been a beta tester for an Envato feature
  • Sells items exclusively on Envato Market
  • Has sold $250,000+ on Envato Market
  • Had an item featured on Envato Market
+7 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 ?

214 posts
  • Has referred 1+ members
  • Has collected 50+ items on Envato Market
  • Has been part of the Envato Community for over 5 years
  • Sells items exclusively on Envato Market
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
1646 posts Building the Web.
  • Has been a beta tester for an Envato feature
  • Sells items exclusively on Envato Market
  • Has sold $250,000+ on Envato Market
  • Had an item featured on Envato Market
+7 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:

214 posts
  • Has referred 1+ members
  • Has collected 50+ items on Envato Market
  • Has been part of the Envato Community for over 5 years
  • Sells items exclusively on Envato Market
agusmu says
2028 posts
  • Made it to the Authors' Hall of Fame
  • Had an item featured on Envato Market
  • Provided great feedback to improve the user experience on Envato Market
  • Interviewed on an Envato blog
+9 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

1646 posts Building the Web.
  • Has been a beta tester for an Envato feature
  • Sells items exclusively on Envato Market
  • Has sold $250,000+ on Envato Market
  • Had an item featured on Envato Market
+7 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