NYCPHP Meetup

NYPHP.org

[nycphp-talk] Creating Avatar Images

Ben Sgro (ProjectSkyLine) ben at projectskyline.com
Fri Oct 12 19:20:31 EDT 2007


Quick thing,

Just a bit more info for those that want to help debug:

The contents of the imageObject print_r( ) call:

Image_Transform_Driver_GD Object ( [imageHandle] => [old_image] => [image] 
=> 8752441244710006fed1bf.jpg [type] => [img_x] => [img_y] => [new_x] => 
[new_y] => [lib_path] => [resized] => [_options] => Array ( [quality] => 75 
[scaleMethod] => smooth [canvasColor] => Array ( [0] => 255 [1] => 255 [2] 
=> 255 ) [pencilColor] => Array ( [0] => 0 [1] => 0 [2] => 0 ) [textColor] 
=> Array ( [0] => 0 [1] => 0 [2] => 0 ) ) [keep_settings_on_save] => 
[_supported_image_types] => Array ( [png] => rw [gif] => rw [jpeg] => rw 
[wbmp] => rw ) [_error] => [_programs] => Array ( ) [default_text_params] => 
Array ( [text] => Default text [x] => 10 [y] => 20 [color] => red [font] => 
Arial.ttf [size] => 12 [angle] => 0 [resize_first] => ) )

The dir's are chmod 777 just because.


if ( $stateObject->Get('do_avatar') == TRUE )
        {
            $uploadObject = new FileUpload(0666);
            $fileName = $uploadObject->MoveFile(USER_IMAGES_PATH, 
'uploadImage');
            error_log($fileName);
            if ( $fileName == PROC_FAILURE )
            {   /* There has been an unrecoverable error. */
                error_log(USER_IMAGES_PATH . ' directory does not exist');
                return PROC_FAILURE;
            }

            $imageObject =& Image_Transform::factory('');
            $imageObject->load($fileName);
            if ( PEAR::isError($imageObject) )
            {
                error_log("imageObject->load( ) error");
            }
            $imageObject->fit(90, 110);
            if ( PEAR::isError($imageObject) )
            {
                error_log("imageObject->fit( ) error");
            }
            $newFileName  = substr($fileName, 0, strrpos($fileName,"."));
            $newFileName .= '.png';
            $imageObject->save(USER_IMAGES_PATH . $newFileName);
            if ( PEAR::isError($imageObject) )
            {
                error_log("imageObject->save( ) error");
            }
            print_r($imageObject);
        }

^ The entire code snippet.

- Ben

Ben Sgro, President
ProjectSkyLine - Defining New Horizons
+1 718.487.9368 (N.Y. Office)

Our company: www.projectskyline.com
Our products: www.project-contact.com

This e-mail is confidential information intended only for the use of the 
individual to whom it is addressed.
----- Original Message ----- 
From: "Ben Sgro (ProjectSkyLine)" <ben at projectskyline.com>
To: "NYPHP Talk" <talk at lists.nyphp.org>
Sent: Friday, October 12, 2007 7:17 PM
Subject: Re: [nycphp-talk] Creating Avatar Images


> Hello Again,
>
> No, I don't want to roll my own at all. I want the quickest way possible
> to do this.
>
> The code I have *should* work, but doesn't....
>
>            $imageObject =& Image_Transform::factory('');
>            $imageObject->load($fileName);
>            if ( PEAR::isError($imageObject) )
>            {
>                error_log("imageObject->load( ) error");
>            }
>            $imageObject->fit(90, 110);
>            if ( PEAR::isError($imageObject) )
>            {
>                error_log("imageObject->fit( ) error");
>            }
>            $newFileName  = substr($fileName, 0, strrpos($fileName,"."));
>            $newFileName .= '.png';
>            $imageObject->save(USER_IMAGES_PATH . $newFileName);
>            if ( PEAR::isError($imageObject) )
>            {
>                error_log("imageObject->save( ) error");
>            }
>            print_r($imageObject);
>
> I can't figure it out. No PEAR errors are getting thrown,
> but the image is never being saved.
>
> Any ideas? The file is getting uploaded to the server, I can see that.
>
> Thanks!
>
> - Ben
>
> Ben Sgro, President
> ProjectSkyLine - Defining New Horizons
> +1 718.487.9368 (N.Y. Office)
>
> Our company: www.projectskyline.com
> Our products: www.project-contact.com
>
> This e-mail is confidential information intended only for the use of the 
> individual to whom it is addressed.
> ----- Original Message ----- 
> From: "Jon Baer" <jonbaer at jonbaer.com>
> To: "NYPHP Talk" <talk at lists.nyphp.org>
> Sent: Friday, October 12, 2007 12:24 PM
> Subject: Re: [nycphp-talk] Creating Avatar Images
>
>
> Well I was not suggesting to fully use the gravatar site itself
> (although you can scale to whatever size you wish for your avatar
> using &size=n), I think they recognize anything > 80px to not be an
> "avatar" ... your question dealt w/ the security of such images + the
> technique w/ the MD5 hash of email address link to an image path was
> more the idea.
>
> There actually is an excellent library if you want to roll your
> own ... http://phpthumb.sourceforge.net.  It includes this hashing
> mechanism already.
>
> - Jon
>
> On Oct 11, 2007, at 10:18 PM, Ben Sgro ((ProjectSkyLine)) wrote:
>
>> Hello Jon,
>>
>> A gravatar, or globally recognized avatar, is quite simply an 80×80 
>> pixel avatar image that follows you from weblog to weblog appearing 
>> beside your name when you comment on gravatar enabled sites.  Avatars 
>> help identify your posts on web forums, so why not on weblogs?
>>
>> Not exactly what Im looking for. In fact, this has external  dependencies 
>> on the gravatar.com site.
>>
>> Thanks anyways.
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
>
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
>
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php 




More information about the talk mailing list