1744 posts Building the Web.
  • Top Monthly Author
  • Trendsetter
  • Weekly Top Seller
  • Beta Tester
+10 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 ?

223 posts
  • Affiliate Level 1
  • Collector Level 3
  • 7 Years of Membership
  • 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
1744 posts Building the Web.
  • Top Monthly Author
  • Trendsetter
  • Weekly Top Seller
  • Beta Tester
+10 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:

223 posts
  • Affiliate Level 1
  • Collector Level 3
  • 7 Years of Membership
  • Exclusive Author
agusmu
says
2280 posts
  • Top Monthly Author
  • Weekly Top Seller
  • Community Superstar
  • Industrious API Inventor
+16 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

1744 posts Building the Web.
  • Top Monthly Author
  • Trendsetter
  • Weekly Top Seller
  • Beta Tester
+10 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