Jump to content

Problem creating a thumbnail

- - - - -

  • Please log in to reply
1 reply to this topic

#1
Alhazred

Alhazred

    Learning Programmer

  • Members
  • PipPipPip
  • 99 posts
I have a form which alloes to upload an image, once the image is uploaded I have to create a thumbnail from it.
This is my code
$immagine_sorgente = $uploadpath.$filename;
$estensione = strtolower(substr($immagine_sorgente, strrpos($immagine_sorgente, "."), strlen($immagine_sorgente)-strrpos($immagine_sorgente, ".")));
if($estensione==".jpeg" || $estensione==".jpg"){
    $handle_immagine = imagecreatefromjpeg($immagine_sorgente);
}elseif($estensione==".gif"){
    $handle_immagine = imagecreatefromgif($immagine_sorgente);
}elseif($estensione==".png"){
    $handle_immagine = imagecreatefrompng($immagine_sorgente);
}
$width=imagesx($handle_immagine);
$height=imagesy($handle_immagine);

$newX=150;
$newY=round(($height/$width)*$newX);

$tmp_immagine = imagecreatetruecolor($newX, $newY);
$handle_immagine_adattata = imagecopyresampled($tmp_immagine, $handle_immagine, 0, 0, 0, 0, $newX, $newY, $width, $height);
imagejpeg($handle_immagine_adattata, $uploadpath.'thumb_'.$filename, 75);
imagedestroy($tmp_immagine);
the image upload works correctly, but the thumb is not created, even if the paths are correct.
What's wrong?

#2
Alhazred

Alhazred

    Learning Programmer

  • Members
  • PipPipPip
  • 99 posts
Solved using imagecopyresized() in place of imagecopyresampled()




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users