forum.coppermine-gallery.net
No Support => General discussion (no support!) => Topic started 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.
-
Yes, 1.3 support was the wrong place since the question had nothing to do with coppermine.
-
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
-
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);
?>
-
Although allowed, using <? to open a php block isn't recommended. Use <?php instead.
-
Good point, thanks.
-
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
-
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.
-
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
-
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.
-
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
-
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.
-
@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
-
@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. :)