jeddik
08-10-2006, 04:59 AM
I have been trying to de-bug my thumb creator.
It runs without out error but it is not placing any image into the destination directory.
Can you please help me de-bug it - can you see any error or what should I insert to debub it ?
You will see that I have 2 debud lines and they display expected data.
here is the script:
function makeThumbnail($source, $t_ht,$N_pix_n) {
$image_info = getImageSize($source) ; // see EXIF for faster way
echo print_r($image_info);
switch ($image_info['mime']) {
case 'image/gif':
if (imagetypes() & IMG_GIF) { // not the same as IMAGETYPE
$o_im = imageCreateFromGIF($source) ;
} else {
$ermsg = 'GIF images are not supported<br />';
}
break;
case 'image/jpeg':
if (imagetypes() & IMG_JPG) {
exec(":d/web/jhead -purejpg ".$source); // cleans up jpg headers
$o_im = imageCreateFromJPEG($source) ;
} else {
$ermsg = 'JPEG images are not supported<br />';
}
break;
case 'image/png':
if (imagetypes() & IMG_PNG) {
$o_im = imageCreateFromPNG($source) ;
} else {
$ermsg = 'PNG images are not supported<br />';
}
break;
case 'image/wbmp':
if (imagetypes() & IMG_WBMP) {
$o_im = imageCreateFromWBMP($source) ;
} else {
$ermsg = 'WBMP images are not supported<br />';
}
break;
default:
$ermsg = $image_info['mime'].' images are not supported<br />';
break;
} // end switch
IF (!isset($ermsg)) {
$o_wd = imagesx($o_im) ;
$o_ht = imagesy($o_im) ;
// thumbnail width = target * original width / original height
$t_wd = round($t_ht * $o_wd / $o_ht) ;
if(imageistruecolor($o_im)){
$N_image = @imagecreatetruecolor($t_wd, $t_ht) or die('Invalid resize dimmensions');
imageAlphaBlending($N_image, false); // this disabled so that saveAlpha can be used.
imageSaveAlpha($N_image, true);
}
else{
$N_image = @imagecreate($t_wd, $t_ht) or die('Invalid resize dimmensions');
if(false !== ($trans = @imagecolorsforindex($source, imagecolortransparent($source)))){
$trans = ImageColorAllocate($N_image, $trans['red'], $trans['green'], $trans['blue']);
imagefilledrectangle($N_image, 0, 0, $w - 1, $h - 1, $trans);
imagecolortransparent($N_image, $trans);
}
} // end else
echo " $t_wd, $t_ht, $o_wd, $o_ht";
imagecopyresampled($N_image, $o_im, 0, 0, 0, 0, $t_wd, $t_ht, $o_wd, $o_ht);
imageJPEG($N_image,$N_pix_n,80);
imageDestroy($o_im);
imageDestroy($N_image);
} // end IF
return (isset($ermsg)?$ermsg:NULL);
} // End of Function
IF (isset($_POST['run_mn'])){
$N_pix1 = strip_tags(trim($_FILES['upLoad1']["name"]));
if($N_pix1 != ""){
if($_FILES['upLoad1']['tmp_name'] == "none") {
$message1 = "Picture file 1 did not successfully upload" ;
$message2 = "Check the file size. Must be less than 500K";
require_once ("a_picts_fm.php");
exit();
} // endif
if(!ereg("image",$_FILES['upLoad1']['type'])) {
$message1 = "The file you have selected for Picture 1 is not";
$message2 = "a recognised picture file - Please try a different file"; require_once ("a_picts_fm.php");
exit();
} // endif
$pix1_y = "y";
} // endif
else{
$N_pix1 = "none";
} // end else
/*
* Everything seems ok - so we create the thumbnails from the temp_files.
*/
$ad_ref = 5;
if($pix1_y == "y"){
$image = $_FILES['upLoad1']['tmp_name'];
$N_pix1 = makeThumbnail($image, 120,$N_pix1);
$N_pix1 = time()."-".$N_pix1."_small";
$destination = 'D:\Web\images'."\\".$N_pix1;
move_uploaded_file($N_pix_n,$destination);
require_once("Letter_yod.inc");
$connection = mysql_connect($host,$user,$password)
or die ("Couldn't connect to server.");
$db = mysql_select_db($database, $connection)
or die ("Couldn't select database.");
$sql = "UPDATE events SET image1 = '$N_pix1'
WHERE ad_ref = '$ad_ref' ";
mysql_query($sql) or die("could not execute events UPDATE PICTURES query");
} // endif
} // end BIG IF
ELSE {
include_once("z_resize_fm.php");
exit();
} // end ELSE
and this is the form:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html>
<head>
<title>Untitled</title>
</head>
<body>
<div style='width:600px; position:absolute; left:200px; top:400px' >
<form name="main_fm" enctype ="multipart/form-data" action="z_resize.php" method="POST">
<input type="hidden" name="run_mn" value="yes" /> <input type="file" size="50" id = "u1" name="upLoad1" >
<br />
<input type="submit" Value = "Upload">
</div>
</body>
</html>
Thanks for any help.
It runs without out error but it is not placing any image into the destination directory.
Can you please help me de-bug it - can you see any error or what should I insert to debub it ?
You will see that I have 2 debud lines and they display expected data.
here is the script:
function makeThumbnail($source, $t_ht,$N_pix_n) {
$image_info = getImageSize($source) ; // see EXIF for faster way
echo print_r($image_info);
switch ($image_info['mime']) {
case 'image/gif':
if (imagetypes() & IMG_GIF) { // not the same as IMAGETYPE
$o_im = imageCreateFromGIF($source) ;
} else {
$ermsg = 'GIF images are not supported<br />';
}
break;
case 'image/jpeg':
if (imagetypes() & IMG_JPG) {
exec(":d/web/jhead -purejpg ".$source); // cleans up jpg headers
$o_im = imageCreateFromJPEG($source) ;
} else {
$ermsg = 'JPEG images are not supported<br />';
}
break;
case 'image/png':
if (imagetypes() & IMG_PNG) {
$o_im = imageCreateFromPNG($source) ;
} else {
$ermsg = 'PNG images are not supported<br />';
}
break;
case 'image/wbmp':
if (imagetypes() & IMG_WBMP) {
$o_im = imageCreateFromWBMP($source) ;
} else {
$ermsg = 'WBMP images are not supported<br />';
}
break;
default:
$ermsg = $image_info['mime'].' images are not supported<br />';
break;
} // end switch
IF (!isset($ermsg)) {
$o_wd = imagesx($o_im) ;
$o_ht = imagesy($o_im) ;
// thumbnail width = target * original width / original height
$t_wd = round($t_ht * $o_wd / $o_ht) ;
if(imageistruecolor($o_im)){
$N_image = @imagecreatetruecolor($t_wd, $t_ht) or die('Invalid resize dimmensions');
imageAlphaBlending($N_image, false); // this disabled so that saveAlpha can be used.
imageSaveAlpha($N_image, true);
}
else{
$N_image = @imagecreate($t_wd, $t_ht) or die('Invalid resize dimmensions');
if(false !== ($trans = @imagecolorsforindex($source, imagecolortransparent($source)))){
$trans = ImageColorAllocate($N_image, $trans['red'], $trans['green'], $trans['blue']);
imagefilledrectangle($N_image, 0, 0, $w - 1, $h - 1, $trans);
imagecolortransparent($N_image, $trans);
}
} // end else
echo " $t_wd, $t_ht, $o_wd, $o_ht";
imagecopyresampled($N_image, $o_im, 0, 0, 0, 0, $t_wd, $t_ht, $o_wd, $o_ht);
imageJPEG($N_image,$N_pix_n,80);
imageDestroy($o_im);
imageDestroy($N_image);
} // end IF
return (isset($ermsg)?$ermsg:NULL);
} // End of Function
IF (isset($_POST['run_mn'])){
$N_pix1 = strip_tags(trim($_FILES['upLoad1']["name"]));
if($N_pix1 != ""){
if($_FILES['upLoad1']['tmp_name'] == "none") {
$message1 = "Picture file 1 did not successfully upload" ;
$message2 = "Check the file size. Must be less than 500K";
require_once ("a_picts_fm.php");
exit();
} // endif
if(!ereg("image",$_FILES['upLoad1']['type'])) {
$message1 = "The file you have selected for Picture 1 is not";
$message2 = "a recognised picture file - Please try a different file"; require_once ("a_picts_fm.php");
exit();
} // endif
$pix1_y = "y";
} // endif
else{
$N_pix1 = "none";
} // end else
/*
* Everything seems ok - so we create the thumbnails from the temp_files.
*/
$ad_ref = 5;
if($pix1_y == "y"){
$image = $_FILES['upLoad1']['tmp_name'];
$N_pix1 = makeThumbnail($image, 120,$N_pix1);
$N_pix1 = time()."-".$N_pix1."_small";
$destination = 'D:\Web\images'."\\".$N_pix1;
move_uploaded_file($N_pix_n,$destination);
require_once("Letter_yod.inc");
$connection = mysql_connect($host,$user,$password)
or die ("Couldn't connect to server.");
$db = mysql_select_db($database, $connection)
or die ("Couldn't select database.");
$sql = "UPDATE events SET image1 = '$N_pix1'
WHERE ad_ref = '$ad_ref' ";
mysql_query($sql) or die("could not execute events UPDATE PICTURES query");
} // endif
} // end BIG IF
ELSE {
include_once("z_resize_fm.php");
exit();
} // end ELSE
and this is the form:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html>
<head>
<title>Untitled</title>
</head>
<body>
<div style='width:600px; position:absolute; left:200px; top:400px' >
<form name="main_fm" enctype ="multipart/form-data" action="z_resize.php" method="POST">
<input type="hidden" name="run_mn" value="yes" /> <input type="file" size="50" id = "u1" name="upLoad1" >
<br />
<input type="submit" Value = "Upload">
</div>
</body>
</html>
Thanks for any help.