feign3
asked on
Corrupt thumbnails with imagejpeg()
I have created a script to create and upload a thumbnail of a selected image however, once in a while the thumbnail comes out corrupt as seen in this link: http://www.starfieldmedia.com/thumb_problem.htm
Is anyone familiar with this problem?
Is anyone familiar with this problem?
no, dont ever encountered such a problem. you might want to give us your code and your system on which you perform the code (php version, gd-library version...)
ASKER
Hi AmigoJack,
Here's the data you requested:
PHP Version 4.4.2
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
System: FreeBSD 5.4-STABLE
Here's the code (variable assignments not included):
function thumbnail($image_path,$thu mb_path,$i mage_name, $thumb_wid th)
{
$src_img = imagecreatefromjpeg("$imag e_path/$im age_name") ;
if (!isset($HTTP_GET_VARS['ma xwidth'])) $max_width=150; else $max_width=($HTTP_GET_VARS ['maxwidth ']);
if (!isset($HTTP_GET_VARS['ma xheight']) ) $max_height=600; else $max_height=($HTTP_GET_VAR S['maxheig ht']);
$size=GetImageSize("../PIC S/".$image _name);
$width =$size[0];
$height=$size[1];
$x_ratio = $max_width / $width;
$y_ratio = $max_height / $height;
if ( ($width <= $max_width) && ($height <= $max_height)) {
$tn_width=$width;
$tn_height=$height;
}
else if (($x_ratio * $height) < $max_height) {
$tn_height = ceil($x_ratio * $height);
$tn_width =$max_width;
}
else {
$tn_width = ceil($y_ratio * $width);
$tn_height=$max_height;
}
$new_w = $tn_width;
//$diff=$origw/$new_w;
//$new_h=$new_w;
$new_h = $tn_height;
$dst_img = imagecreate($new_w,$new_h) ;
imagecopyresized($dst_img, $src_img,0 ,0,0,0,$ne w_w,$new_h ,imagesx($ src_img),i magesy($sr c_img));
imagejpeg($dst_img, "$thumb_path/TN_$image_nam e",100);
return true;
}
thumbnail("../PICS","../PI CS",$imgf, 150);
This doesn't happen to every thumbnail... maybe one in every 5.
Here's the data you requested:
PHP Version 4.4.2
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
System: FreeBSD 5.4-STABLE
Here's the code (variable assignments not included):
function thumbnail($image_path,$thu
{
$src_img = imagecreatefromjpeg("$imag
if (!isset($HTTP_GET_VARS['ma
if (!isset($HTTP_GET_VARS['ma
$size=GetImageSize("../PIC
$width =$size[0];
$height=$size[1];
$x_ratio = $max_width / $width;
$y_ratio = $max_height / $height;
if ( ($width <= $max_width) && ($height <= $max_height)) {
$tn_width=$width;
$tn_height=$height;
}
else if (($x_ratio * $height) < $max_height) {
$tn_height = ceil($x_ratio * $height);
$tn_width =$max_width;
}
else {
$tn_width = ceil($y_ratio * $width);
$tn_height=$max_height;
}
$new_w = $tn_width;
//$diff=$origw/$new_w;
//$new_h=$new_w;
$new_h = $tn_height;
$dst_img = imagecreate($new_w,$new_h)
imagecopyresized($dst_img,
imagejpeg($dst_img, "$thumb_path/TN_$image_nam
return true;
}
thumbnail("../PICS","../PI
This doesn't happen to every thumbnail... maybe one in every 5.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.