Hi guys!
I’m trying to generate thumbnail images in WordPress. The easiest way would have been to use the EXIF suite of functions, but the guys behind WordPress, in their infinite wisdom, decided to strip out the image previews from any photographs uploaded via their Media Library.
So, I’m now reliant on GD Library instead. However, I can’t seem to get to work either, and I don’t know why.
I’m using a function written by David Walsh, which should work, but doesn’t:
function make_thumb($src, $desired_width) {
/* read the source image */
$source_image = imagecreatefromjpeg($src);
$width = imagesx($source_image);
$height = imagesy($source_image);
/* find the "desired height" of this thumbnail, relative to the desired width */
$desired_height = floor($height * ($desired_width / $width));
/* create a new, "virtual" image */
$virtual_image = imagecreatetruecolor($desired_width, $desired_height);
/* copy source image at a resized size */
imagecopyresized($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height);
/* create the physical thumbnail image to its destination */
imagejpeg($virtual_image);
}
You may notice that I’ve stripped out the destination variable, as I want this to print directly to screen.
Instead of generating an image, per the imagejpeg() function, it’s just burping out raw code.
Now, I’ve tried encoding this with the base64_encode() function, I even tried decoding with it’s sibling, and I’ve also tried the [URL=“http://php.net/manual/en/function.header.php”]header() function, but nothing works.
I can’t use a Plugin, as I have very specific requirements to meet.
Any suggestions would be greatly appreciated.