Forum Moderators: coopster

Message Too Old, No Replies

Profile Pictures

Limiting the size of pictures in profiles

         

mechanical messiah

7:19 pm on Sep 16, 2003 (gmt 0)

10+ Year Member



I'm trying to limit picture widths in a persons profile, currently. I don't host the person's picture, so it'd have to basicly check to see if the picture that's remotely hosted is beyond the given width, and then return an error message if it is.

is there a way i can do this?

wruk999

7:54 pm on Sep 16, 2003 (gmt 0)

10+ Year Member



[uk.php.net...]

Its the GetImagesize php function. Have a read through, and see if it helps. ;)

wruk999

tranceaddict

9:35 pm on Sep 16, 2003 (gmt 0)

10+ Year Member



I created a function that gets the size of an image, as well as a length in pixels, and limits the height or width of the image by the length in pixels, it also retains the relative size. So basically it will scale the image to max height/width.

it will return an array with keys, 'width' and 'height' that you can use to set the size of your image in html.


function ResizeImage($imageNamePath, $maxSize = 150) {
$size = getimagesize($imageNamePath);
$new_width = $size[0];
$new_height = $size[1];
if ($size[0] > $maxSize) {
$new_width = $maxSize;
$multiplier = $size[0] / $maxSize;
$new_height = $size[1] / $multiplier;
} elseif ($size[1] > $maxSize) {
$new_height = $maxSize;
$multiplier = $size[1] / $maxSize;
$new_width = $size[0] / $multiplier;
}
$imageSize['width'] = $new_width;
$imageSize['height'] = $new_height;

return $imageSize;
}

$sizeAry = ResizeImage("picture.jpg", 200);

echo "<img src=\"picture.jpg\" width=\"" . $sizeAry['width'] . "\" height=\"" . $sizeAry['height'] . "\">";

jatar_k

9:56 pm on Sep 16, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld tranceaddict!

tranceaddict

10:42 pm on Sep 16, 2003 (gmt 0)

10+ Year Member



thanks! always read, never signed up.

Here to give help to those who need it ;)

Just to make up for all those times, i needed help as well.

vincevincevince

9:28 am on Sep 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



one concern, when will you check it? every time it's displayed? (--> high server / bandwidth load to transfer remote images and find their size) or when it's first chosen? (--> people just changing the picture at the given URL after sucessful checks)

i'd suggest that you store the filesize of the image after it's chosn, you can then check the filesize hasn't changed... if changed then check again, as filessize won't need you to transfer the whole image every time to your server.