Current location: Hot Scripts Forums » Programming Languages » PHP » thumbnail creator


thumbnail creator

Reply
  #1 (permalink)  
Old 05-24-05, 11:53 AM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
thumbnail creator

I am looking for a php thumbnail creator that will:

* read a directory for all the jpegs in it
* resize each picture to 100x100 and save it as a "$name_thumbnail.jpg"
* return all the thumbnail urls

I dont want the original jpegs affected at all! Can anyone find any function like this??
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Reply With Quote
  #2 (permalink)  
Old 05-24-05, 12:46 PM
Acecool's Avatar
Acecool Acecool is offline
Aspiring Coder
 
Join Date: Nov 2003
Posts: 506
Thanks: 0
Thanked 0 Times in 0 Posts
I can create this if you like.

Its a matter of reading the directory, getting the file properties, the name etc, setting the images to a session and then creating the images, refresh on every page, if the "first" key is done, delete from array and do next, if failed add to end.
__________________
Check Acecoolco.com for PHP Tutorials, and other tuts
If you plan on contacting me, please read this: Legal Terms & Conditions
Reply With Quote
  #3 (permalink)  
Old 05-24-05, 01:08 PM
dennispopel dennispopel is offline
Coding Addict
 
Join Date: Mar 2005
Posts: 263
Thanks: 0
Thanked 0 Times in 0 Posts
As it may seem simple at the first glance, what are you going to do if new pics are added to the directory you already processed? I would suggest that a thumbnail be generated as the files are uploaded. However, if they are added by, e.g., FTP, then I would suggest that thumbs are created in real time (imagine someone names a file mypic_thumbnail)? The thumb generator could as well employ caching to reduce traffic and load.
__________________
onPHP5.com - PHP5: Articles, News, Tutorials, Interviews, Software and more
Reply With Quote
  #4 (permalink)  
Old 05-24-05, 02:39 PM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
no the generated images will be stored in a db and then compared, u dont have to worry about it just if someone could point me in the right direction wud be great...
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Reply With Quote
  #5 (permalink)  
Old 05-24-05, 03:50 PM
Acecool's Avatar
Acecool Acecool is offline
Aspiring Coder
 
Join Date: Nov 2003
Posts: 506
Thanks: 0
Thanked 0 Times in 0 Posts
Id use glob() or readdir() to get *.jpg
Then use the image functions to generate if they do not exist.
__________________
Check Acecoolco.com for PHP Tutorials, and other tuts
If you plan on contacting me, please read this: Legal Terms & Conditions
Reply With Quote
  #6 (permalink)  
Old 05-24-05, 04:37 PM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
its the resizing and creating new img bit that i am stuck on!
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Reply With Quote
  #7 (permalink)  
Old 05-24-05, 05:10 PM
Acecool's Avatar
Acecool Acecool is offline
Aspiring Coder
 
Join Date: Nov 2003
Posts: 506
Thanks: 0
Thanked 0 Times in 0 Posts
Well, as I am still writing up new content for the new ACMS, the thumbnail generation tutorial isnt up yet :-/

Here are a few pointers though:

Need the extension to determine which function to use
PHP Code:

        $Extended_File_Info pathinfo($Image);

        
$File_Extension $Extended_File_Info['extension'];

        switch (
$File_Extension)
        {
            case 
'jpg':
                if (
function_exists('imagecreatefromjpeg'))
                {
                    
$Source_Image imagecreatefromjpeg($Image);
                }
                else
                {
                    return 
FALSE;
                }
            break;
        
            case 
'gif':
                if (
function_exists('imagecreatefromgif'))
                {
                    
$Source_Image imagecreatefromgif($Image);
                }
                else
                {
                    return 
FALSE;
                }
            break;
    
            case 
'png':
                if (
function_exists('imagecreatefrompng'))
                {
                    
$Source_Image imagecreatefrompng($Image);
                }
                else
                {
                    return 
FALSE;
                }
            break;
        } 
Thats for the source image, the big image if you will...

Now, you create a new image:
And copy the source image to the new one..
PHP Code:

$New_Image imagecreatetruecolor($New_Width$New_Height);

imagecopyresized($New_Image$Source_Image0000$New_Width$New_Height$Width$Height); 
Also, width and height are from the main image:
list($Width, $Height) = getimagesize($Source_Image);


Output and save it:
imagepng($New_Image, $Output_Image);
Saves the new image as 'Output image should be the new name with extension'


Edit:
Sorry its so sloppy at the moment, its still not optimized and all..
__________________
Check Acecoolco.com for PHP Tutorials, and other tuts
If you plan on contacting me, please read this: Legal Terms & Conditions
Reply With Quote
  #8 (permalink)  
Old 05-24-05, 05:14 PM
Sabu Sabu is offline
Junior Code Guru
 
Join Date: Sep 2004
Posts: 458
Thanks: 0
Thanked 0 Times in 0 Posts
I've made a script that, whanever you look at the thumbnail page, it goes through each picture in a given directory. If there exists a thumbnail for it, it shows the thumbnail, otherwise it creates one and shows that. Fast loading except for the first time each thumb is shown.

Currently it makes all thumbnails in the same directory, named as an md5 hash of the original file for duplicates.

I don't have it handy within reasonable reaching space for this early in the morning, but message me perhaps and I'll see what I can do.
Reply With Quote
  #9 (permalink)  
Old 05-24-05, 05:56 PM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
well ace this is what I got...

PHP Code:

<?php


function imgsource($Image) {
$Extended_File_Info pathinfo($Image); 
        
$File_Extension $Extended_File_Info['extension']; 

        switch (
$File_Extension
        { 
            case 
'jpg'
                if (
function_exists('imagecreatefromjpeg')) 
                { 
                    
$Source_Image imagecreatefromjpeg($Image); 
                } 
                else 
                { 
                    return 
FALSE
                } 
            break; 
         
            case 
'gif'
                if (
function_exists('imagecreatefromgif')) 
                { 
                    
$Source_Image imagecreatefromgif($Image); 
                } 
                else 
                { 
                    return 
FALSE
                } 
            break; 
     
            case 
'png'
                if (
function_exists('imagecreatefrompng')) 
                { 
                    
$Source_Image imagecreatefrompng($Image); 
                } 
                else 
                { 
                    return 
FALSE
                } 
            break; 
        } 
}


$Source_Image imgsource("truck.jpg");
list(
$Width$Height) = getimagesize("truck.jpg");
$New_Image imagecreatetruecolor("100""100");
$Output_Image imagecopyresized($New_Image$Source_Image0000"100""100"$Width$Height);

$done imagepng($New_Image$Output_Image);

$filename rand(100000,999999)."temp.jpg";
$tempfile fopen($filename"w+");
fwrite($tempfile$done);
fclose($tempfile);

echo 
"<img src=\"$filename\">";
?>
Warning: imagecopyresized(): supplied argument is not a valid Image resource
Warning: imagepng(): Invalid filename '' on line 50


__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Reply With Quote
  #10 (permalink)  
Old 05-25-05, 03:46 AM
Acecool's Avatar
Acecool Acecool is offline
Aspiring Coder
 
Join Date: Nov 2003
Posts: 506
Thanks: 0
Thanked 0 Times in 0 Posts
remove:
$Source_Image = imgsource("truck.jpg");
__________________
Check Acecoolco.com for PHP Tutorials, and other tuts
If you plan on contacting me, please read this: Legal Terms & Conditions
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need thumbnail image show large image separately, on mouseover Cre8tvnrg JavaScript 12 03-05-08 11:01 AM
Saving thumbnail into Database astro PHP 0 02-16-05 07:33 AM
Help need to add thumbnail page Pabstman Script Requests 1 06-29-04 03:37 PM
photo gallery w/formfields for each thumbnail mikeyzc PHP 2 05-28-04 01:16 PM
photo gallery w/form fields for each thumbnail mikeyzc Script Requests 0 05-28-04 06:48 AM


All times are GMT -5. The time now is 06:46 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.