fireice87 Posted May 5, 2008 Share Posted May 5, 2008 Hey I've got a form that lets users upload 3 images, these are then stored in a temp folder. I Then resized the 3 images. I'am attempting to re-code this re-sizing script into a function as good practice, but it doesnt seem that the file paths that are stored in the variables $path1,$path2,$path3 make it to the function, the error messages thrown suggests this. Thanks for any help should hopefully be quite simple for those familiar with wrinting functions. cheers To call the function id give it the variables to use(do these need to be global?) [code] <?php image_handler($path1, $path2, $path3, $prod_id); ?> The function <?php function image_handler() { mkdir("../Images/small_product_image/$prod_id/"); mkdir("../Images/large_product_image/$prod_id/"); $c = 0; if ($c < 2) { if($c=0) {$image = $path1;} else if($c=1) {$image = $path2;} else $image = $path3; $ext = substr($image, -3); //get extension $x = @getimagesize($image); // get image size $sw = $x[0]; // image width $sh = $x[1]; // image height $w = 150; //new width $wb = 350; //new width for large image $h = (100 / ($sw / $w)) * .01; $h = @round ($sh * $h); //new hieght $hb = (100 / ($sw / $wb)) * .01; $hb = @round ($sh * $hb); //new hieght $im = @ImageCreateFromJPEG ($image) or // Read JPEG Image $im = @ImageCreateFromPNG ($image) or // or PNG Image $im = @ImageCreateFromGIF ($image) or // or GIF Image $im = false; // If image is not JPEG, PNG, or GIF $thumb = @ImageCreateTrueColor ($w, $h); // Create the resized image destination $thumbb = @ImageCreateTrueColor ($wb, $hb); @ImageCopyResampled ($thumb, $im, 0, 0, 0, 0, $w, $h, $sw, $sh); // Copy from image source, resize it, and paste to image destination @ImageCopyResampled ($thumbb, $im, 0, 0, 0, 0, $wb, $hb, $sw, $sh); $filename = "../Images/small_product_image/$prod_id/$c.".$ext; $filenameb = "../Images/large_product_image/$prod_id/$c.".$ext; imagejpeg($thumb,$filename,100); imagejpeg($thumbb,$filenameb,100); $c++; } } ?> Error messages Warning: mkdir() [function.mkdir]: File exists Warning: mkdir() [function.mkdir]: File exists Warning: Division by zero Warning: Division by zero Warning: imagejpeg(): supplied argument is not a valid Image resource in Warning: imagejpeg(): supplied argument is not a valid Image resource in [/code] Quote Link to comment https://forums.phpfreaks.com/topic/104262-solved-functions-and-variable-scope-issue/ Share on other sites More sharing options...
moselkady Posted May 5, 2008 Share Posted May 5, 2008 You needed to declare those passed variables in the function argument list <?php function image_handler($path1, $path2, $path3, $prod_id) { ..... } ?> Quote Link to comment https://forums.phpfreaks.com/topic/104262-solved-functions-and-variable-scope-issue/#findComment-533750 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.