FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Avatars





snowboardalliance
I want to know the best way to do this. I have a member system. I want them to have avatars. I want the avatars to be restricted to x by y pixels, but they can be smaller. I think it would be easier to allow the avatars to be off-site and just hotlinked, but I don't know how to check the size. Should I just have it so users upload thier avatar and I scale it if necessary and store it on the server? Also, can I see some example code?

Thanks.
MrBaseball34
On this page:
http://us3.php.net/manual/en/function.getimagesize.php

See the user comments by egingell at sisna dot com:
Code:

 * mixed image_info( file $file [, string $out] )
 *
 * Returns information about $file.
snowboardalliance
OK, how can I take an image (let's say remotely hosted) and resize it AND save it in a folder on my site? I think that will work for me. I'm just not too sure on all the opening an image and saving it part. Thanks
Philip
u cannot do remotely,
u need to copy the image first to your site and checked it.

use this function for copy,

Code:
copy("http://www.google.com/image.jpg",tempnam("/temporaly folder", "FOO_PREFIX");)


and recheck your image with getimagesize.
snowboardalliance
Philip wrote:
u cannot do remotely,
u need to copy the image first to your site and checked it.

use this function for copy,

Code:
copy("http://www.google.com/image.jpg",tempnam("/temporaly folder", "FOO_PREFIX");)


and recheck your image with getimagesize.


Wow that tempnam() function should help. One more thing, I'm not familiar with GD and images, so once I get the image size and find it too big, I'll have the new size in variables. How do I save the image scaled down?
Philip
using imagecopyresampled function.
i hope this can help u, and this only work for gif picture, u need to change the mime header type to other and function also, for working with other picture.

ex :
Code:
$imagefile="picture.gif";
   header('Content-type: image/gif');
   list($width_orig, $height_orig) = getimagesize($imagefile);
   $width = 300;
   $height = 300;
   $image_p = imagecreatetruecolor($width, $height);
   $image = imagecreatefromgif($filename);
   imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
   imagegif($image_p, null, 100);            
snowboardalliance
Philip wrote:
using imagecopyresampled function.
i hope this can help u, and this only work for gif picture, u need to change the mime header type to other and function also, for working with other picture.

ex :
Code:
$imagefile="picture.gif";
   header('Content-type: image/gif');
   list($width_orig, $height_orig) = getimagesize($imagefile);
   $width = 300;
   $height = 300;
   $image_p = imagecreatetruecolor($width, $height);
   $image = imagecreatefromgif($filename);
   imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
   imagegif($image_p, null, 100);            


Thanks, and using .png or .jpg I just need to change that in the header and the "imagegif()" part? Everything else is the same?

One last thing, how do I use this script like after the avatar has been entered? I just don't get it because of the header() part, which means the page is served as an image. I want exactly what you said, but have the image saved in a folder as like "avatar34242.gif". Thanks for your help so far.
Philip
to png
Code:
$imagefile="picture.png";
   header('Content-type: image/png');
   list($width_orig, $height_orig) = getimagesize($imagefile);
   $width = 300;
   $height = 300;
   $image_p = imagecreatetruecolor($width, $height);
   $image = imagecreatefrompng($filename);
   imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
   imagepng($image_p, null, 100);     


u need to create specific php file for read as a image
ex :
image.php that contain
Code:
$imagefile="picture.png";
   $imagefile=$_GET["imagefile"];
   header('Content-type: image/png');
   list($width_orig, $height_orig) = getimagesize($imagefile);
   $width = 300;
   $height = 300;
   $image_p = imagecreatetruecolor($width, $height);
   $image = imagecreatefrompng($filename);
   imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
   imagepng($image_p, null, 100);     


and on other php or html file u can call it by
Other.php
Code:
Below this is a image php <br><img src="image.php?imagefile=www.google.com/picture.png">
snowboardalliance
Philip wrote:
to png
Code:
$imagefile="picture.png";
   header('Content-type: image/png');
   list($width_orig, $height_orig) = getimagesize($imagefile);
   $width = 300;
   $height = 300;
   $image_p = imagecreatetruecolor($width, $height);
   $image = imagecreatefrompng($filename);
   imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
   imagepng($image_p, null, 100);     


u need to create specific php file for read as a image
ex :
image.php that contain
Code:
$imagefile="picture.png";
   $imagefile=$_GET["imagefile"];
   header('Content-type: image/png');
   list($width_orig, $height_orig) = getimagesize($imagefile);
   $width = 300;
   $height = 300;
   $image_p = imagecreatetruecolor($width, $height);
   $image = imagecreatefrompng($filename);
   imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
   imagepng($image_p, null, 100);     


and on other php or html file u can call it by
Other.php
Code:
Below this is a image php <br><img src="image.php?imagefile=www.google.com/picture.png">


I was thinking I might just have to do the <img> thing, but is there anyway to save it so I don't have to resize it everytime it is viewed? Like save image.php?imagefile=www.google.com/picture.png as image5302093.png somewhere.
Philip
your surely a newbie at php ?

then just use copy function
ex:

Code:
copy("image.php?imagefile=www.google.com/picture.png","test.png");


this will copy the image to test.png.
snowboardalliance
Philip wrote:
your surely a newbie at php ?

then just use copy function
ex:

Code:
copy("image.php?imagefile=www.google.com/picture.png","test.png");


this will copy the image to test.png.


Newbie at images/files in php actually. Thanks for all your help.
Philip
nah, it;s ok Smile
you are welcome #i think i learned that code from some else here too also hehe.. Smile #
Maryndor
Hehe... I'll remember that forum with the questions about MySQL and Image Stuff. Just people can't think about anything other ... Razz
Related topics
Avatars and Signatures for sale!
My greatest custom made avatars (open-source :D)
Turn off Remote Avatars.
:: 1,000 :: Avatars ::
.::Avatars::.
Avatars
please increase the size limit for avatars
Nice Avatars!!!
avatars in phpbb
Veiwing Animated icons/avatars
I have made some FriHost avatars
Custom Sigs/Avatars(Static or Animated) 6frih$ each
Custom Banner/Avatars & LOGOS!
Avatars!
Where can I find some cool Anime Avatars!!!
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.