Jump to content

Problem w/ resizing image ...


bsamson

Recommended Posts

Hello, I am trying to take a image file and resize it based on # of total pixels. When I run the script it does NOTHING to the pic ... it just maintains it's original size. Any assistance would be greatly appreciated!

 

CODE:

<?

function imageResize($width, $height, $target) { 

// takes the larger size of the width and height and applies the  
// formula accordingly...this is so this script will work  
// dynamically with any size image 

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 
// can plug this function inside an image tag and just get the 

return "width=\"$width\" height=\"$height\""; 

} 

$mysock = getimagesize("members/girl.jpg");

?>

<!-using a standard html image tag, where you would have the  
width and height, insert your new imageResize() function with  
the correct attributes --> 

<img src="members/girl.jpg" <? imageResize($mysock[0], $mysock[1], 500); ?>>

Link to comment
Share on other sites

what exactly do you want to do? changing the .jpges size on the server or just the html output?

 

if you want to change the picture directly check out

http://www.phpfreaks.com/forums/index.php/topic,147163.0.html

 

if not.. add ECHO to your line (because you want to output the return value of the function)

<img src="members/girl.jpg" <? echo imageResize($mysock[0], $mysock[1], 500); ?>

 

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.