forum.coppermine-gallery.net

No Support => General discussion (no support!) => Topic started by: hama on November 18, 2004, 10:40:09 pm

Title: random pictures as avatar
Post by: hama on November 18, 2004, 10:40:09 pm
Some of you have random pictures as avatar. Looks very nice.

Is this a difficult code?   :o  I'd like to have it too ...

I don't know if this is the right place to ask, if not, please move it to the right place.

Title: Re: random pictures as avatar
Post by: Tranz on November 18, 2004, 11:07:31 pm
Yes, 1.3 support was the wrong place since the question had nothing to do with coppermine.
Title: Re: random pictures as avatar
Post by: Joachim Müller on November 19, 2004, 09:53:12 am
the script that I use as random avatar is specific to my site - there's little point in posting the code. There are nice tutorials to be found on the internet on how to accomplish such a rotation with one file - I recommend doing a little search on google.

Joachim
Title: Re: random pictures as avatar
Post by: rphMedia on November 19, 2004, 12:51:13 pm
Here's one of many, many ways.  Pretty self-explanitory.  Should get you started though.  Gots to have GD installed, obviously  :)  Make your images @80x80 and point to the file.

Also, lots of tricks with this (like telling the folder to treat jpg as php)

<?
header("Content-type: image/jpeg");
$imgname[] = "image1.jpg";
$imgname[] = "image2.jpg";
$imgname[] = "image3.jpg";
$imgname[] = "image4.jpg";
$imgname[] = "image5.jpg";
$rand_image = array_rand($imgname);
$im = imagecreatefromjpeg ($imgname[$rand_image]);
imagejpeg ($im);
imagedestroy ($im);
?>
Title: Re: random pictures as avatar
Post by: kegobeer on November 19, 2004, 10:27:16 pm
Although allowed, using <? to open a php block isn't recommended.  Use <?php instead.
Title: Re: random pictures as avatar
Post by: rphMedia on November 19, 2004, 11:46:05 pm
Good point, thanks.
Title: Re: random pictures as avatar
Post by: hama on January 08, 2005, 03:50:33 pm

The following script (from rphMedia) works great with *.jpg.

Is there a possibility to make something with "else / if" about "Content-type: image/jpeg" and "Content-type: image/gif" so that it would work with *.jpg and *.gif?

Code: [Select]
<?php
header
("Content-type: image/jpeg");
$imgname[] = "image1.jpg";
$imgname[] = "image2.jpg";
$imgname[] = "image3.jpg";
$imgname[] = "image4.jpg";
$imgname[] = "image5.jpg";
$rand_image array_rand($imgname);
$im imagecreatefromjpeg ($imgname[$rand_image]);
imagejpeg ($im);
imagedestroy ($im);
?>


Thanks for a little bit support (I know it's not really relevant to coppermine, sorry).

hama
Title: Re: random pictures as avatar
Post by: Tranz on January 08, 2005, 06:52:32 pm
Try the script from here (http://www.lunarforums.com/forum/viewtopic.php?p=75242#75242). It will go through a folder looking for files, so you don't have to hard code the names. Makes it much easier to add/delete the collection. ;) There are others like it around the internet, but I knew where it was so I didn't have to search for it. :) Plus it takes care of gif and jpg extensions.
Title: Re: random pictures as avatar
Post by: hama on January 08, 2005, 08:46:48 pm
Thanks! I read the whole thread at lunar..., tried out every possibility but it doesn't work.  :-\\

rphMedia's is the only script working in my forum (with *.jpg and unfortunatly not with *.gif).

Maybe it has to do with safe_mode (it's on ...  and I'm not the webhoster).

Is there no possibility to build in this one:

Code: [Select]
$ext = substr("$avatars[$file]",-4);
switch ($ext) {
   case ".gif":
      Header("content-type:image/gif");
   break;
   case ".jpg":
      Header("content-type:image/jpeg");
   break;
};


somewhere in this one:

Code: [Select]
<?php
header
("Content-type: image/jpeg");
$imgname[] = "avatar1.jpg";
$imgname[] = "avatar2.jpg";
$imgname[] = "avatar3.gif";
$rand_image array_rand($imgname);
$im imagecreatefromjpeg ($imgname[$rand_image]);
imagejpeg ($im);
imagedestroy ($im);
?>

Thanks

hama
Title: Re: random pictures as avatar
Post by: Tranz on January 08, 2005, 08:51:14 pm
That's too bad. We don't have safe_mode on so I guess that's why there's no problem using it. I did a search to understand safe_mode and came across an apropos cartoon to describe safe_mode. http://www.futurequest.net/Safe_Mode_Off.php

Also it may not work if your forum doesn't allow non-image extensions. Is that an issue? There is a workaround. You name the file with an image extension. Use .htaccess to redirect that file to the actual script. That is, if you can edit .htaccess.
Title: Re: random pictures as avatar
Post by: hama on January 08, 2005, 09:26:35 pm

I can edit .htaccess but first I have to read and learn about .htaccess.

Thanks for your help!

I spent now a whole day trying to fix this "silly random avatar problem". Before I get crazy it's maybe better to stop thinking about it and enjoying the weekend (far away from computers) ... I need a break because I can't fix it at the moment.

Have a good time  :)

hama
Title: Re: random pictures as avatar
Post by: rphMedia on January 08, 2005, 11:53:36 pm
I'm not home right now, but I'll show you a few ways to do it, both .htaccess and gifs. Ensure you have the correct GD on your server. The one that re-supports gif.
Title: Re: random pictures as avatar
Post by: hama on January 09, 2005, 03:21:29 pm
@TranzNDance and Ron:

Everything works great now! I had to take another script, this one:

Code: [Select]
<?php
### config
$folder './images';

### output
$d dir($folder);
$list = array();
while (
$file $d->read()) {
    if (
preg_match('#\.(tiff|png|gif|jpe?g)$#i'$file)) {
        
$list[] = $folder.'/'.$file;
    }
}
$rand array_rand($list);
$type explode('.'$list[$rand]);
header('Content-Type: image/'.$type[count($type)-1]);
$fp fopen($list[$rand], 'rb');
fpassthru($fp); 
exit(); 
?>


First I tried with

Code: [Select]
<?php
echo file_get_contents($list[$rand]);
?>



at the end of the script. This didn't work because my webhoster doesn't update his server (php version 4.2.2 ...). I wrote him but no answer. So I changed to

Code: [Select]
<?php
$fp 
fopen($list[$rand], 'rb');
fpassthru($fp);
?>



at the end of the script. This one works now great (with *.jpg, *.gif, *.tiff and *.png)!

@TranzNDance: Your avatar and signature are very nice! Your're a crazy girl!

Thanks for all the help!

hama
Title: Re: random pictures as avatar
Post by: Tranz on January 09, 2005, 09:57:41 pm
@TranzNDance: Your avatar and signature are very nice! Your're a crazy girl!
Thanks. :) They're kind of like self-imposed PHP homework projects. They make me study and apply PHP concepts that I might not otherwise do for the heck of it.

I'm glad you got the script to work. :)