Link to home
Start Free TrialLog in
Avatar of mmc98dl1
mmc98dl1Flag for Australia

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\upload.php on line 24 Warning: imagesx(): supplied argument is not a valid Image resource in c:\inetpub\wwwroot\sixfive.co.uk\upload.php on line 25 Warning: imagesy(): supplied argument is not a valid Image resource in c:\inetpub\wwwroot\sixfive.co.uk\upload.php on line 26 Warning: imagecopyresampled(): supplied argument is not a valid Image resource in c:\inetpub\wwwroot\sixfive.co.uk\upload.php on line 40 Warning: imagedestroy(): supplied argument is not a valid Image resource in c:\inetpub\wwwroot\sixfive.co.uk\upload.php on line 47

Here is my code:

<?
include("accesscontrol.php");

$title="Administration";
session_start();
include("header.txt");

      $uploadDir = "C:/inetpub/wwwroot/domain.com/images/";
      $fileName = $_FILES['file']['tmp_name'];
      $userfileName = str_replace(" ","_",$_FILES['file']['name']);
    move_uploaded_file($fileName, $uploadDir. $userfileName);

      $source = imagecreatefromjpeg($uploadDir. $userfileName);
      $dest = imagecreate(100, 100);

    $system=explode(".",$userfileName);
    if (preg_match("/jpg|jpeg/",$system[1])){
        $src_img=imagecreatefromjpeg($uploadDir. $userfileName);
            echo("jpg");
    }
    if (preg_match("/png/",$system[1])){
        $src_img=imagecreatefrompng($uploadDir. $userfileName);
    }

      $original_x=imageSX($src_img);
    $original_y=imageSY($src_img);
    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=ImageCreateTrueColor($thumb_w,$thumb_h);
    imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$original_x,$original_y);
      if (preg_match("/png/",$system[1])){
        imagepng($dst_img,$uploadDir."th_".$userfileName);
    } else {
        imagejpeg($dst_img,$uploadDir."th_".$userfileName);
    }
    imagedestroy($dst_img);
    imagedestroy($src_img);

    $sql = "Insert into Image (ImageName,ImageDescription,uploaddate,imagefile,thumbnailfile,viewcount,AlbumId) VALUES ('".$HTTP_POST_VARS['name']."','".$HTTP_POST_VARS['description']."',now(),'".$userfileName."','th_".$userfileName."',0,".$HTTP_POST_VARS['galleryId'].")";
      dbDo(&$result,$sql);

include("footer.txt");      
?>

Can anyone help?
ASKER CERTIFIED SOLUTION
Avatar of Michael701
Michael701
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial