bugzy Posted July 25, 2012 Share Posted July 25, 2012 I was researching on how will I able to resize an image on image retrieve and I got this function <?php function me_resize_jpeg( $original_image, $new_height, $new_width, $filename ) { // Resize the original image $image_resized = imagecreatetruecolor($new_width, $new_height); $image_tmp = imagecreatefromjpeg ($original_image); imagecopyresampled($image_resized, $image_tmp, 0, 0, 0, 0, $new_width, $new_height, $width, $height); imagejpeg($image_resized, $filename.".jpg", 100); imagedestroy($image_resized); } ?> and I'm using it this way <?php $target_path = "../images_item/"; me_resize_jpeg($target_path.$edit_id.".jpg",'100','50',$target_path.$edit_id); ?> But I'm getting this error: Undefined variable: width in C:\wamp\www\runa\includes\functions.php on line 58 Undefined variable: height in C:\wamp\www\runa\includes\functions.php on line 58 The function is only asking for four parameters and I don't if the function is missing something... Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/266249-undefined-variable-in-imagecreatefromjpeg/ Share on other sites More sharing options...
xyph Posted July 25, 2012 Share Posted July 25, 2012 You got a bad function. Find one that works Quote Link to comment https://forums.phpfreaks.com/topic/266249-undefined-variable-in-imagecreatefromjpeg/#findComment-1364394 Share on other sites More sharing options...
Barand Posted July 25, 2012 Share Posted July 25, 2012 As the error messages tell you, $width and $height have no values. They should contain the width and height of the original image. Put $width = imagesx($image_tmp); $height = imagesy($image_tmp); before calling imagecopyresampled() Quote Link to comment https://forums.phpfreaks.com/topic/266249-undefined-variable-in-imagecreatefromjpeg/#findComment-1364397 Share on other sites More sharing options...
NomadicJosh Posted July 25, 2012 Share Posted July 25, 2012 @Barand got to it before I could. From the php page, there are a few examples of how to get the variables of the original image. One example is: list($width, $height) = getimagesize($original_image); Quote Link to comment https://forums.phpfreaks.com/topic/266249-undefined-variable-in-imagecreatefromjpeg/#findComment-1364398 Share on other sites More sharing options...
bugzy Posted July 26, 2012 Author Share Posted July 26, 2012 Just a side question guys... Does imagecreatefromjpeg() actually resize the original image on the server side, or it's being resize only on the end-user? Quote Link to comment https://forums.phpfreaks.com/topic/266249-undefined-variable-in-imagecreatefromjpeg/#findComment-1364412 Share on other sites More sharing options...
jazzman1 Posted July 26, 2012 Share Posted July 26, 2012 @bugzy, go to my web server and see how does my script work is. I've used jQuery Image Cropping Plugin and php scripts to resize images. If you like it I'll give you the scripts. URL to server is: http://kaneffbrookside.ca/stdimitar/login.php user: jazzman pass: password Go to Crop New Image jQuery Image Cropping Plugin - http://deepliquid.com/content/Jcrop.html Quote Link to comment https://forums.phpfreaks.com/topic/266249-undefined-variable-in-imagecreatefromjpeg/#findComment-1364423 Share on other sites More sharing options...
Barand Posted July 26, 2012 Share Posted July 26, 2012 Just a side question guys... Does imagecreatefromjpeg() actually resize the original image on the server side, or it's being resize only on the end-user? imagecreatefromjpeg() doesn't do any resizing - it just converts a jpeg image to a GD image. Quote Link to comment https://forums.phpfreaks.com/topic/266249-undefined-variable-in-imagecreatefromjpeg/#findComment-1364424 Share on other sites More sharing options...
bugzy Posted July 26, 2012 Author Share Posted July 26, 2012 Just a side question guys... Does imagecreatefromjpeg() actually resize the original image on the server side, or it's being resize only on the end-user? imagecreatefromjpeg() doesn't do any resizing - it just converts a jpeg image to a GD image. From the word converting, so the original image will be a GD file now literally? and imagecreatefromjpeg() doesn't do any and image duplication? like the duplicate one will going to be the GD file? and the original will still be there as is? Just want to be sure guys.. Quote Link to comment https://forums.phpfreaks.com/topic/266249-undefined-variable-in-imagecreatefromjpeg/#findComment-1364429 Share on other sites More sharing options...
bugzy Posted July 26, 2012 Author Share Posted July 26, 2012 Alright I get it now guys! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/266249-undefined-variable-in-imagecreatefromjpeg/#findComment-1364449 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.