Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 03-31-2005, 09:09 AM bilder auslesen.
Novice Talker

Posts: 9
Trades: 0
Also ich habe hier folgenden code der auch einwanfrei funktioniert:

Code:
while($foto = readdir($fd))
{
    if  (preg_match("/\.(jpg|gif|png)$/i", $foto))
    {
       echo "<center><a href=\"$dir/$foto\"><p>";
       echo "<img src=\"$dir/$foto\" align=middle border=0>";
       echo "</a> $foto<br>\n";
    }
}
(das ist jetzt nur ein auszug)
ich möchte aber noch attribute zu dem bild dazufügen. (z.B. width<100, dass nur bilder mit width<100 angezeigt werden)
Kann mir jemand sagen wie ich das machen kann? Ich wollte es in die if schleife mit einbinden, weiss aber nicht so recht wie.

Last edited by Bloods; 03-31-2005 at 09:49 AM..
Bloods is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-31-2005, 02:53 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
To find the width of an image you'll probably need the GD libraries. Does your host have them installed?
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 03-31-2005, 09:51 PM
Novice Talker

Posts: 9
Trades: 0
oh...damit kenn ich mich überhaupt nicht aus. oh jeh.
Ich hätte nicht egdacht dass das so kompliziert werden könnte...
es gibt also keine 'einfache' möglichkeit?

ich hbe auch noch eine zweite frage.
wei kann ich erreichen dass aus der dir ein random bild angezeigt wird?

Last edited by Bloods; 03-31-2005 at 10:16 PM..
Bloods is offline
Reply With Quote
View Public Profile
 
Old 04-01-2005, 07:49 AM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
To find out if your host has GD, create a small script on the server with the following code:

PHP Code:
phpinfo(); 
and open it in your browser. Find the part of the page marked 'gd' and see if it is enabled.

If it is, then you can get the size of an image as follows:

PHP Code:

if( *JPG IMAGE* ) {
  
$img imagecreatefromjpeg($foto);
}
else if ( *
GIF IMAGE* ) {
  
$img imagecreatefromgif($foto);
}
else if ( *
PNG IMAGE* ) {
  
$img imagecreatefrompng($foto);
}
  
$size_x imagesx($img);
  
$size_y imagesy($img); 
To get a random image I'd just read the filenames into an array and then pick one:

PHP Code:
$files = Array();
while(
$foto readdir($fd))
{
    if  (
preg_match("/\.(jpg|gif|png)$/i"$foto))
    {
        
$files[] = $foto;
    }
}
$random_foto $files[rand(0,count($files)-1)];
echo 
"<center><a href=\"$dir/$random_foto\"><p>";
echo 
"<img src=\"$dir/$random_foto\" align=middle border=0>";
echo 
"</a> $random_foto<br>\n"
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 04-03-2005, 04:12 PM
Novice Talker

Posts: 9
Trades: 0
Thanks a lot really, you helped me a great deal!
I have one problem though.
I looked up the php info and gd is enabled.
However if I use your code I get following error:

parse error, unexpected '*'
Bloods is offline
Reply With Quote
View Public Profile
 
Old 04-03-2005, 04:28 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
Ah sorry - the *'s were there to show it was just an example - I was writing quickly.
Try this instead:

PHP Code:
$extension strtolower(substr($foto,-3));
if( 
$extension == 'jpg' || strtolower(substr($foto,-4)) == 'jpeg') {
  
$img imagecreatefromjpeg($foto);
}
else if ( 
$extension == 'gif' ) {
  
$img imagecreatefromgif($foto);
}
else if ( 
$extension == 'png' ) {
  
$img imagecreatefrompng($foto);
}
  
$size_x imagesx($img);
  
$size_y imagesy($img); 
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 04-03-2005, 07:31 PM
Novice Talker

Posts: 9
Trades: 0
Thanks a lot. Slowly I'm learning more and more about php. Hopefully I'll be good at it once >.<
Anyway, it is working fine now.
You're great!

Greetings
Bloods
Bloods is offline
Reply With Quote
View Public Profile
 
Old 04-04-2005, 01:35 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
Kein problem
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Reply     « Reply to bilder auslesen.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.32060 seconds with 12 queries