mmc98dl1
asked on
thumbnail creation with GD2
I am trying to manipulate an uploaded image from a form. The system is PHP 4.3.3 and GD2 2.0.15 compatible reports on phpinfo().
I am following the PHP manual by using GD2 but I get the following errors:
Warning: imagesx(): supplied argument is not a valid Image resource in c:\inetpub\wwwroot\sixfive .co.uk\upl oad.php on line 24 Warning: imagesx(): supplied argument is not a valid Image resource in c:\inetpub\wwwroot\sixfive .co.uk\upl oad.php on line 25 Warning: imagesy(): supplied argument is not a valid Image resource in c:\inetpub\wwwroot\sixfive .co.uk\upl oad.php on line 26 Warning: imagecopyresampled(): supplied argument is not a valid Image resource in c:\inetpub\wwwroot\sixfive .co.uk\upl oad.php on line 40 Warning: imagedestroy(): supplied argument is not a valid Image resource in c:\inetpub\wwwroot\sixfive .co.uk\upl oad.php on line 47
Here is my code:
<?
include("accesscontrol.php ");
$title="Administration";
session_start();
include("header.txt");
$uploadDir = "C:/inetpub/wwwroot/domain .com/image s/";
$fileName = $_FILES['file']['tmp_name' ];
$userfileName = str_replace(" ","_",$_FILES['file']['nam e']);
move_uploaded_file($fileNa me, $uploadDir. $userfileName);
$source = imagecreatefromjpeg($uploa dDir. $userfileName);
$dest = imagecreate(100, 100);
$system=explode(".",$userf ileName);
if (preg_match("/jpg|jpeg/",$ system[1]) ){
$src_img=imagecreatefromjp eg($upload Dir. $userfileName);
echo("jpg");
}
if (preg_match("/png/",$syste m[1])){
$src_img=imagecreatefrompn g($uploadD ir. $userfileName);
}
$original_x=imageSX($src_i mg);
$original_y=imageSY($src_i mg);
if ($original_x > $original_y) {
$thumb_w=100;
$thumb_h=$original_y*(100/ $original_ x);
}
if ($original_x < $original_y) {
$thumb_w=$original_x*(100/ $original_ y);
$thumb_h=100;
}
if ($original_x == $original_y) {
$thumb_w=100;
$thumb_h=100;
}
$dst_img=ImageCreateTrueCo lor($thumb _w,$thumb_ h);
imagecopyresampled($dst_im g,$src_img ,0,0,0,0,$ thumb_w,$t humb_h,$or iginal_x,$ original_y );
if (preg_match("/png/",$syste m[1])){
imagepng($dst_img,$uploadD ir."th_".$ userfileNa me);
} else {
imagejpeg($dst_img,$upload Dir."th_". $userfileN ame);
}
imagedestroy($dst_img);
imagedestroy($src_img);
$sql = "Insert into Image (ImageName,ImageDescriptio n,uploadda te,imagefi le,thumbna ilfile,vie wcount,Alb umId) VALUES ('".$HTTP_POST_VARS['name' ]."','".$H TTP_POST_V ARS['descr iption']." ',now(),'" .$userfile Name."','t h_".$userf ileName."' ,0,".$HTTP _POST_VARS ['galleryI d'].")";
dbDo(&$result,$sql);
include("footer.txt");
?>
Can anyone help?
I am following the PHP manual by using GD2 but I get the following errors:
Warning: imagesx(): supplied argument is not a valid Image resource in c:\inetpub\wwwroot\sixfive
Here is my code:
<?
include("accesscontrol.php
$title="Administration";
session_start();
include("header.txt");
$uploadDir = "C:/inetpub/wwwroot/domain
$fileName = $_FILES['file']['tmp_name'
$userfileName = str_replace(" ","_",$_FILES['file']['nam
move_uploaded_file($fileNa
$source = imagecreatefromjpeg($uploa
$dest = imagecreate(100, 100);
$system=explode(".",$userf
if (preg_match("/jpg|jpeg/",$
$src_img=imagecreatefromjp
echo("jpg");
}
if (preg_match("/png/",$syste
$src_img=imagecreatefrompn
}
$original_x=imageSX($src_i
$original_y=imageSY($src_i
if ($original_x > $original_y) {
$thumb_w=100;
$thumb_h=$original_y*(100/
}
if ($original_x < $original_y) {
$thumb_w=$original_x*(100/
$thumb_h=100;
}
if ($original_x == $original_y) {
$thumb_w=100;
$thumb_h=100;
}
$dst_img=ImageCreateTrueCo
imagecopyresampled($dst_im
if (preg_match("/png/",$syste
imagepng($dst_img,$uploadD
} else {
imagejpeg($dst_img,$upload
}
imagedestroy($dst_img);
imagedestroy($src_img);
$sql = "Insert into Image (ImageName,ImageDescriptio
dbDo(&$result,$sql);
include("footer.txt");
?>
Can anyone help?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.