contra10 Posted March 19, 2009 Share Posted March 19, 2009 I concerned about resizing images, currently i resize images by simply stretching them out or making them smaller, but sometimes if i upload a picture that is more horizontal then vertical then the image can become distored or vice versa...is there a way i can upload and resize the image so that the image isn't distorted? Quote Link to comment https://forums.phpfreaks.com/topic/150192-resizing-image-to-proper-resolution/ Share on other sites More sharing options...
MadTechie Posted March 19, 2009 Share Posted March 19, 2009 i probably messed that up. $newSize = 500; if($height > $width) { $width =($width/$height)*$newSize; $height = $newSize; }else{ $height =($height/$width)*$newSize; $width= $newSize; } Quote Link to comment https://forums.phpfreaks.com/topic/150192-resizing-image-to-proper-resolution/#findComment-788772 Share on other sites More sharing options...
contra10 Posted March 19, 2009 Author Share Posted March 19, 2009 how should i put it in this code...this is to reze for larger image <?php // Create MySQL login values and // set them to your login information. $username = "root"; $password = ""; $host = "localhost"; $database = "userimages"; // Make the connect to MySQL or die // and display an error. $link = mysql_connect($host, $username, $password); if (!$link) { die('Could not connect: ' . mysql_error()); } $connect = mysql_select_db($database) or die("Can not select the database: ".mysql_error()); $id = $_GET['id']; if(!isset($id) || empty($id)){ die("Please select your image!"); }else{ $query = mysql_query('SELECT `image` FROM `tbl_images` WHERE `userid`= "'.$id.'"'); $row = mysql_fetch_assoc($query); $content = $row['image']; $desired_width = 300; $desired_height = 225; $im = imagecreatefromstring($content)or die("Can not select the database: ".mysql_error());; $new = imagecreatetruecolor($desired_width, $desired_height)or die("Can not select the database: ".mysql_error());; $x = imagesx($im); $y = imagesy($im); imagecopyresampled($new, $im, 0, 0, 0, 0, $desired_width, $desired_height, $x, $y)or die("Can not select the database: ".mysql_error());; imagedestroy($im); header('Content-type: ' . $row['type'] .''); imagejpeg($new, null, 85); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/150192-resizing-image-to-proper-resolution/#findComment-788777 Share on other sites More sharing options...
contra10 Posted March 20, 2009 Author Share Posted March 20, 2009 sry but kinda confused....how does it work? Quote Link to comment https://forums.phpfreaks.com/topic/150192-resizing-image-to-proper-resolution/#findComment-789138 Share on other sites More sharing options...
redarrow Posted March 20, 2009 Share Posted March 20, 2009 read this please using gd function. http://icfun.blogspot.com/2009/03/php-resizing-image-using-php-gd.html Quote Link to comment https://forums.phpfreaks.com/topic/150192-resizing-image-to-proper-resolution/#findComment-789139 Share on other sites More sharing options...
contra10 Posted March 20, 2009 Author Share Posted March 20, 2009 still experiencing trouble. im trying to get it from the url. is there another way when doing that i get this error Fatal error: Call to undefined function resamplimgimagecopyresampled() in /home/username/public_html/profile/index.php on line 79 my image url is created from the code above and i use this in profile image display $large_image = imagecreatefromjpeg( "http://www.domain.com/image/viewlarge.php?id=$id" ); ## provided the dimension of the new smaller image $x = 180;$y = 180; ## create a black blank image with provided dimension $small_image = imagecreatetruecolor($x,$y); ## Just copy the larger image into the smaller image using resamplimgimagecopyresampled($small_image,$large_image,0,0,0,0,$x,$y,imagesx($large_image),imagesy($large_image)); ## Its always better to free the memory if you don't need thisimagedestroy($large_image); ## Just ignore the file name.# imagejpeg($small_image); ## Once again, free the memeoryimagedestroy($small_image); line 79 being resamplimgimagecopyresampled($small_image,$large_image,0,0,0,0,$x,$y,imagesx($large_image),imagesy($large_image)); Quote Link to comment https://forums.phpfreaks.com/topic/150192-resizing-image-to-proper-resolution/#findComment-789189 Share on other sites More sharing options...
contra10 Posted March 20, 2009 Author Share Posted March 20, 2009 ok i got it, but the image can still be distorted... its the same result as b4 Quote Link to comment https://forums.phpfreaks.com/topic/150192-resizing-image-to-proper-resolution/#findComment-789192 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.