Image Resizing
Posted: Fri Jan 04, 2008 7:56 pm
The following code displays my raw image correctly
however the image is not the size I want it to be, I need it resized to 150x150 (or close to that) so I am using the following
var_dump shows the following
array(7) {
[0]=> int(650)
[1]=> int(478)
[2]=> int(2)
[3]=> string(24) "width="650" height="478""
["bits"]=> int(8) ["channels"]=> int(3) ["mime"]=> string(10) "image/jpeg" }
Which is correct - so I have the following function IMMEDIATELY FOLLOWING THE getimagesize function
Now the question becomes where do I place this function? I have tried the following - which is placed after the function is declared...
However the image remains the original size. How do I get this function to resize the image?
Thank you
Code: Select all
echo "<table align='center' border='0' width='400' >";
echo "<tr>\n
<td align='center'><img border='0' src=\"".htmlspecialchars($imagetouse)."\"></td>
</tr>";
echo "<tr>\n
<td> </td>
</tr>";
echo "</table>\n";Code: Select all
$mysock=getimagesize($imagetouse);array(7) {
[0]=> int(650)
[1]=> int(478)
[2]=> int(2)
[3]=> string(24) "width="650" height="478""
["bits"]=> int(8) ["channels"]=> int(3) ["mime"]=> string(10) "image/jpeg" }
Which is correct - so I have the following function IMMEDIATELY FOLLOWING THE getimagesize function
Code: Select all
$mysock=getimagesize($imagetouse);
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\"";
}Code: Select all
echo "<table align='center' border='0' width='400' >";
echo "<tr>\n
<td align='center'><img border='0' src=\"".htmlspecialchars($imagetouse)."\" imageResize($mysock[0], $mysock[1], 150)
></td>
</tr>";
echo "<tr>\n
<td> </td>
</tr>";
echo "</table>\n";Thank you