bsamson Posted June 28, 2007 Share Posted June 28, 2007 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); ?>> Quote Link to comment Share on other sites More sharing options...
melvincr Posted June 28, 2007 Share Posted June 28, 2007 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); ?> Quote Link to comment 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.