random pictures as avatar random pictures as avatar
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

random pictures as avatar

Started by hama, November 18, 2004, 10:40:09 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

hama

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.

Get up, stand up, stand up for your rights! - Get up, stand up, don't give up the fight!

Tranz

Yes, 1.3 support was the wrong place since the question had nothing to do with coppermine.

Joachim Müller

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

rphMedia

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);
?>

kegobeer

Although allowed, using <? to open a php block isn't recommended.  Use <?php instead.
Do not send me a private message unless I ask for one.  Make your post public so everyone can benefit.

There are no stupid questions
But there are a LOT of inquisitive idiots

rphMedia


hama


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?


<?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
Get up, stand up, stand up for your rights! - Get up, stand up, don't give up the fight!

Tranz

Try the script from here. 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.

hama

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:

$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:

<?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
Get up, stand up, stand up for your rights! - Get up, stand up, don't give up the fight!

Tranz

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.

hama


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
Get up, stand up, stand up for your rights! - Get up, stand up, don't give up the fight!

rphMedia

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.

hama

@TranzNDance and Ron:

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


<?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


<?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


<?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
Get up, stand up, stand up for your rights! - Get up, stand up, don't give up the fight!

Tranz

Quote from: hama on January 09, 2005, 03:21:29 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. :)