Jump to content

PHP image resize problem


kpetsche20

Recommended Posts

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

<?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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.