Page 1 of 1

black block for thumbnail image

Posted: Thu Jul 28, 2005 11:10 am
by lostinphp
The following code returns a black thumbnail size of the original image..ive been trying to get an exact thumbnail image but new to php i find it difficult..if anyone can check these lines of codes and help me..it wud be very useful
thank u

<!doctype html public "-//w3c//dtd html 3.2//en">

<html>

<head>
<title></title>
<meta name="GENERATOR" content="Arachnophilia 4.0">
<meta name="FORMATTER" content="Arachnophilia 4.0">
</head>

<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
<?php

$MAX_FILE_SIZE = 150000;

// Dossier de destination du fichier
$folder = "./upimg/";

$allowed_types = array("image/bmp", "image/gif", "image/jpeg", "image/jpg", "multipart/x-zip", "video/msvideo");
$fname = $HTTP_POST_FILES['fichier']['name'];
$ftype = $HTTP_POST_FILES['fichier']['type'];
$fsize = $HTTP_POST_FILES['fichier']['size'];
$ftmp = $HTTP_POST_FILES['fichier']['tmp_name'];


if(!in_array($ftype, $allowed_types)){$error = 1;}


if($fize > $MAX_FILE_SIZE){$error = 2;}

// Le fichier n'existe pas déjà
if(file_exists($folder."m_".$fname)){$error = 3;}


if(copy($ftmp,''.$folder.''.$fname.'')){$error = 0;}


switch($error){
case'0':
echo("Fichier correctement envoyé.");
break;
case'1':
echo("Format de fichier incorrecte.");
break;
case'2':
echo("Fichier trop volumineux.");
break;
case'3':
echo("Fichier déjà existant.");
break;
}


$n_width="65"; // Fix the width of the thumb nail images
$n_height="65"; // Fix the height of the thumb nail imaage
$tsrc="thimg/$fname";
$msrc="upimg/$fname";


// Path where thumb nail image will be stored

if (!($ftype =="image/pjpeg" OR $ftype=="image/gif"))
{
if($ftype=="image/jpeg")
{
$im=ImageCreateFromJPEG($fname);
$width=ImageSx($im); // Original picture width is stored
$height=ImageSy($im); // Original picture height is stored
$newimage=ImageCreateTruecolor($n_width,$n_height);
ImageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
ImageJPEG($newimage,$tsrc);
chmod("$tsrc",0777);
chmod("$msrc",0777);

}}

?>



</body>

</html>

Posted: Thu Jul 28, 2005 1:15 pm
by pickle
2 things: Try echoing all the width and height variables you have. If any of them are zero, you'll get a black image. Also, use imagecopyresampled() instead of imagecopyresized() if you have GD 2.0 - it makes a MUCH nicer thumbnail - a lot smoother.