thure Posted July 11, 2008 Share Posted July 11, 2008 Hi there, I'm basically trying to crop and resize images received from $_FILES in a form. The errors I've been getting this entire evening have been these: Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/willshow/public_html/queermcgill/admincaledit2.php on line 108 Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/willshow/public_html/queermcgill/admincaledit2.php on line 109 The two lines it's referring to are the two commands at the end of this source code: //POSTERLINK if(isset($_FILES['fposterlink'])){ $curwidth=1; $curheight=1; $posterlink=""; $uploaddir = '/uploaddir/eventimg/'; $ext=strtolower(file_extension($_FILES['fposterlink']['name'])); $uploadtemppath = $_FILES['fposterlink']['tmp_name']; $posterlink = $uploaddir.$keyid."posterlink.".$ext; $cursize=getimagesize($uploadtemppath); $curwidth =$cursize[0]; $curheight=$cursize[1]; $imgrsc=imagecreate(174,261); $tmprsc=imagecreate(1,1); $cropx = 0; $cropy = 0; $cropw=$curwidth; $croph=$curheight; $ratio=(2/3); if(($curwidth/$curheight)!=$ratio){ if($curwidth > $ratio*$curheight){//too wide $cropx = ($curwidth-($ratio*$curheight))/2; $cropyw = $ratio*$curheight; } if($curwidth < $ratio*$curheight){//too tall $cropy = ($curheight-($curwidth/$ratio))/2; $croph = $curwidth/$ratio; } }//end IF not within ratio switch($ext){ case "jpg": $tmprsc=imagecreatefromjpeg($uploadtemppath); break; case "jpeg": $tmprsc=imagecreatefromjpeg($uploadtemppath); break; case "gif": $tmprsc=imagecreatefromgif($uploadtemppath); break; case "png": $tmprsc=imagecreatefrompng($uploadtemppath); break; } imagecopyresampled('$imgrsc','$tmprsc',0,0,$cropx,$cropy,174,261,$cropw,$croph); imagejpeg($imgsrc,$posterlink,80); }//end check for POSTERLINK upload //END POSTERLINK Am I missing something? I tried my best before posting on a forum – I almost never hit a dead end like this, but now I'm utterly clueless. Thanks very much and best wishes, thure Link to comment https://forums.phpfreaks.com/topic/114219-image-resource-mixup%E2%80%A6/ Share on other sites More sharing options...
Third_Degree Posted July 11, 2008 Share Posted July 11, 2008 do not place $imgsrc in quotes in imagecopyresampled Link to comment https://forums.phpfreaks.com/topic/114219-image-resource-mixup%E2%80%A6/#findComment-587326 Share on other sites More sharing options...
thure Posted July 11, 2008 Author Share Posted July 11, 2008 Okay, that was dumb on my part - I've just fixed it. I get this error now: Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/willshow/public_html/queermcgill/admincaledit2.php on line 108 which is great because it's one less! here is the new source code which produces the error: if(isset($_FILES['fposterlink'])){ $curwidth=1; $curheight=1; $posterlink=""; $uploaddir = '/uploaddir/eventimg/'; $ext=strtolower(file_extension($_FILES['fposterlink']['name'])); $uploadtemppath = $_FILES['fposterlink']['tmp_name']; $posterlink = $uploaddir.$keyid."posterlink.".$ext; $cursize=getimagesize($uploadtemppath); $curwidth =$cursize[0]; $curheight=$cursize[1]; $imgrsc=imagecreate(174,261); $tmprsc=imagecreate(1,1); $cropx = 0; $cropy = 0; $cropw=$curwidth; $croph=$curheight; $ratio=(2/3); if(($curwidth/$curheight)!=$ratio){ if($curwidth > $ratio*$curheight){//too wide $cropx = ($curwidth-($ratio*$curheight))/2; $cropyw = $ratio*$curheight; } if($curwidth < $ratio*$curheight){//too tall $cropy = ($curheight-($curwidth/$ratio))/2; $croph = $curwidth/$ratio; } }//end IF not within ratio switch($ext){ case "jpg": $tmprsc=imagecreatefromjpeg($uploadtemppath); break; case "jpeg": $tmprsc=imagecreatefromjpeg($uploadtemppath); break; case "gif": $tmprsc=imagecreatefromgif($uploadtemppath); break; case "png": $tmprsc=imagecreatefrompng($uploadtemppath); break; } imagecopyresampled($imgrsc,$tmprsc,0,0,$cropx,$cropy,174,261,$cropw,$croph); imagejpeg($imgsrc,$posterlink,80); } does imagecopyresampled not modify the resource $imgrsc, which is already existing? Link to comment https://forums.phpfreaks.com/topic/114219-image-resource-mixup%E2%80%A6/#findComment-587329 Share on other sites More sharing options...
thure Posted July 11, 2008 Author Share Posted July 11, 2008 oh jeez, clerical error! I misspelled $imgrsc $imgsrc because I'm so used to typing 'src.' problem solved! thanks so much! Link to comment https://forums.phpfreaks.com/topic/114219-image-resource-mixup%E2%80%A6/#findComment-587332 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.