Jump to content

[SOLVED] Thumbnail Creation with GD


ratgurrl

Recommended Posts

Can someone tell me what is wrong with this?  Thumbnail is created and saved, but displays as all black!  I'm about to rip my hair out.

 

if (!empty($image_file)) {

	// Temporary upload image name
	$temp_image = IMAGE_DIR . md5(uniqid(rand(), true)) .'.jpg';

	// Get the image dimensions
	$size=GetImageSize( $temp_image );

	// Maximum image width
	$max_width = "350";

	// Maximum image height
	$max_height = "262";

	// Resize the image and save
	$thumbnail = ImageCreateTrueColor( $max_width, $max_height );
	$new_img = ImageCreateFromJPEG( $temp_image );
	ImageCopyResampled( $thumbnail, $new_img, 0, 0, 0, 0, $max_width, $max_height, $size[0],$size[1] );
	ImageJPEG( $thumbnail, THUMBNAILS_DIR . basename($image_file) );
	ImageDestroy( $thumbnail );

	// link full-sided image to the thumbnail image
	$post_content = "<a href=\"" .$imageURL ."/". basename($image_file) ."\" title=\"". $subject ."\" target=\"_blank\"><img class=\"thumb\" src=\"". $thumbURL ."/". basename($image_file) ."\" alt=\"". $subject ."\" border=\"0\" ". $size[3] ." /></a>\n\n" . $post_content;

}


 

From my phpinfo:

 

GD Support enabled

GD Version bundled (2.0.28 compatible)

FreeType Support enabled

FreeType Linkage with freetype

GIF Read Support enabled

GIF Create Support enabled

JPG Support enabled

PNG Support enabled

WBMP Support enabled

XBM Support enabled

Link to comment
https://forums.phpfreaks.com/topic/100865-solved-thumbnail-creation-with-gd/
Share on other sites

<?php
//turn on error reporting
ini_set('error_reporting',E_ALL);
// if not empty and isset image_file
if (!empty($image_file)||isset($image_file)) {

	// Temporary upload image name
	$temp_image = IMAGE_DIR . md5(uniqid(rand(), true)) .'.jpg';

	// Get the image dimensions
	$size=GetImageSize( $temp_image );

	// Maximum image width
	$max_width = "350";

	// Maximum image height
	$max_height = "262";

	// Resize the image and save
	$thumbnail = ImageCreateTrueColor( $max_width, $max_height );
	$new_img = ImageCreateFromJPEG( $temp_image );
	ImageCopyResampled( $thumbnail, $new_img, 0, 0, 0, 0, $max_width, $max_height, $size[0],$size[1] );
	ImageJPEG( $thumbnail, THUMBNAILS_DIR . basename($image_file) );
	ImageDestroy( $thumbnail );

	// link full-sided image to the thumbnail image
	$post_content = "<a href=\"" .$imageURL ."/". basename($image_file) ."\" title=\"". $subject ."\" target=\"_blank\"><img class=\"thumb\" src=\"". $thumbURL ."/". basename($image_file) ."\" alt=\"". $subject ."\" border=\"0\" ". $size[3] ." /></a>\n\n" . $post_content;

}



?>

I love you!

 

Duh, I should have known to turn on error reporting!  Stupid me!

 

All I had to do was to change:

 

$temp_image = IMAGE_DIR . md5(uniqid(rand(), true)) .'.jpg';

 

to

 

$temp_image = IMAGE_DIR . basename($image_file);

 

and then remove:

 

". $size[3] ."

 

from the image path.

 

I feel like a butt head now.  Thanks for the slap!  :)

 

 

 

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.