Jump to content

Problem with Auto thumbnail image creation


sraul

Recommended Posts

I am trying to create thumnail image using following function. This function is giving me correct output on my local machine

(windows OS). I have PHP4 and gd2 library installed on my local machine. 

The server machine is having PHP5 and gd2 library installed.

The problem i am facing is when the same code is executed  on the server (windows OS) the thumnail image for image size

greater than 65KB is getting created but for images less than 65KB, gives black image box. So please tell me what is the

exact problem?


function createthumb($name,$filename,$new_w,$new_h)
{


$system1=explode(".",$name);

$count = count($system1) ;


$system[1] = $system1[$count-1];

//$name = strtolower($name1);

if (preg_match("/jpg|jpeg|JPG|JPEG/",$system[1])){
  echo "<br>";
                // echo "hallo==" . $name ;
        echo "<br>";
  $src_img=imagecreatefromjpeg($name);

  echo "src_img inside if  == "  .$src_img ;
  echo "<br>";
 
  }
if (preg_match("/png|PNG/",$system[1])){$src_img=imagecreatefrompng($name);}

 
$old_x=imageSX($src_img);
$old_y=imageSY($src_img);


  $thumb_w=$new_w;
  $thumb_h=$new_h;


$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h) or die("not working");
$trial = imagecopyresized($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);

echo "dst_img == " . $dst_img ;
echo "<br>";
echo "trial == " . $src_img ;
echo "<br>";


if (preg_match("/png/",$system[1]))
{
 
  imagepng($dst_img,$filename);
} else {
 
  imagejpeg($dst_img,$filename);
}
imagedestroy($dst_img);
imagedestroy($src_img);
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.