1702 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
+8 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 6 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
1702 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
+8 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 6 years
  • Sells items exclusively on Envato Market
agusmu says
2196 posts
  • Located in Europe
  • Made it to the Authors' Hall of Fame
  • Had an item featured on Envato Market
  • Participated in a focus group or interview to improve the user experience on Envato Market
+10 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

1702 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
+8 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..

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by