Advanced search  

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

Pages: [1]   Go Down

Author Topic: random pictures as avatar  (Read 7639 times)

0 Members and 1 Guest are viewing this topic.

hama

  • Contributor
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 229
random pictures as avatar
« 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.

« Last Edit: January 09, 2005, 09:54:56 pm by TranzNDance »
Logged
Get up, stand up, stand up for your rights! - Get up, stand up, don't give up the fight!

Tranz

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Female
  • Posts: 6149
Re: random pictures as avatar
« Reply #1 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.
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: random pictures as avatar
« Reply #2 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
Logged

rphMedia

  • Contributor
  • Coppermine addict
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 515
  • ***muvipix.com***
    • muvipix - Music | Video | Pictures
Re: random pictures as avatar
« Reply #3 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);
?>

kegobeer

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 4637
  • Beer - it does a body good!
    • The Kazebeer Family Website
Re: random pictures as avatar
« Reply #4 on: November 19, 2004, 10:27:16 pm »

Although allowed, using <? to open a php block isn't recommended.  Use <?php instead.
Logged
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

  • Contributor
  • Coppermine addict
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 515
  • ***muvipix.com***
    • muvipix - Music | Video | Pictures
Re: random pictures as avatar
« Reply #5 on: November 19, 2004, 11:46:05 pm »

Good point, thanks.

hama

  • Contributor
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 229
Re: random pictures as avatar
« Reply #6 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
Logged
Get up, stand up, stand up for your rights! - Get up, stand up, don't give up the fight!

Tranz

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Female
  • Posts: 6149
Re: random pictures as avatar
« Reply #7 on: January 08, 2005, 06:52:32 pm »

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.
Logged

hama

  • Contributor
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 229
Re: random pictures as avatar
« Reply #8 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
Logged
Get up, stand up, stand up for your rights! - Get up, stand up, don't give up the fight!

Tranz

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Female
  • Posts: 6149
Re: random pictures as avatar
« Reply #9 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.
Logged

hama

  • Contributor
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 229
Re: random pictures as avatar
« Reply #10 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
Logged
Get up, stand up, stand up for your rights! - Get up, stand up, don't give up the fight!

rphMedia

  • Contributor
  • Coppermine addict
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 515
  • ***muvipix.com***
    • muvipix - Music | Video | Pictures
Re: random pictures as avatar
« Reply #11 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.

hama

  • Contributor
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 229
Re: random pictures as avatar
« Reply #12 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
Logged
Get up, stand up, stand up for your rights! - Get up, stand up, don't give up the fight!

Tranz

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Female
  • Posts: 6149
Re: random pictures as avatar
« Reply #13 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. :)
Logged
Pages: [1]   Go Up
 

Page created in 0.035 seconds with 20 queries.