kpetsche20 Posted June 25, 2008 Share Posted June 25, 2008 I'm trying to resize an image that displays on my page to be 150px. However when i execute the code below it does not resize the image. here is a link to the actual output http://webmasterfreehost.com/testt/test.php <?php //get the image size of the picture and load it into an array $mysock = getimagesize("edit2.5.jpg"); ?> <? function imageResize($width, $height, $target) { //takes the larger size of the width and height and applies the if ($width > $height) { $percentage = ($target / $width); } else { $percentage = ($target / $height); } //gets the new value and applies the percentage, then rounds the value $width = round($width * $percentage); $height = round($height * $percentage); //returns the new sizes in html image tag format...this is so you return "width=\"$width\" height=\"$height\""; } ?> <?php //get the image size of the picture and load it into an array $mysock = getimagesize("edit2.5.jpg"); ?> <img src="edit2.5.jpg" <?php imageResize($mysock[0], $mysock[1], 150); ?>> Link to comment https://forums.phpfreaks.com/topic/111790-php-image-resize-problem/ Share on other sites More sharing options...
Stephen Posted June 25, 2008 Share Posted June 25, 2008 <?php function imageResize($width, $height, $target) { //takes the larger size of the width and height and applies the if ($width > $height) { $percentage = ($target / $width); } else { $percentage = ($target / $height); } //gets the new value and applies the percentage, then rounds the value $width = round($width * $percentage); $height = round($height * $percentage); //returns the new sizes in html image tag format...this is so you return "width=\"$width\" height=\"$height\""; } ?> <?php //get the image size of the picture and load it into an array $mysock = getimagesize("edit2.5.jpg"); ?> <img src="edit2.5.jpg" <?php echo(imageResize($mysock[0], $mysock[1], 150)); ?> /> Try that now. I used echo to show the return value. Link to comment https://forums.phpfreaks.com/topic/111790-php-image-resize-problem/#findComment-573924 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.