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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.