Results 1 to 4 of 4

Thread: Square image thumbnail

  1. #1
    Join Date
    Jan 2007
    Posts
    94
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Cool Square image thumbnail

    So i found a script that does what I want but I'm having trouble "implementing" it. Basically I have all the image file names stored in my table and i want them to all display (the ones uploaded by the particular user logged in) on a page.

    Of course I don't want them enormous, just small thumbnail images would do. I don't want them clickable or anything, i don't even want them to enlarge. But because of the whole portrait and landscape thing, i didn't want to hardcode the size in html. so, after searching i found this script:

    PHP Code:

    function createThumb($source,$dest) {
        
    $thumb_size 150;
        
    $size getimagesize($source);
        
    $width $size[0];
        
    $height $size[1];
        if(
    $width$height) {
            
    $x ceil(($width $height) / );
            
    $width $height;
        } elseif(
    $height$width) {
            
    $y ceil(($height $width) / 2);
            
    $height $width;
        }
        
    $new_im ImageCreatetruecolor($thumb_size,$thumb_size);
        
    $im imagecreatefromjpeg($source);
        
    imagecopyresampled($new_im,$im,0,0,$x,$y,$thumb_size,$thumb_size,$width,$height);
        
    imagejpeg($new_im,$dest,100);

    here's how I'm calling the function:

    PHP Code:
    <?php 
    $path 
    "upload/$pic1";

    echo 
    "<img src=\"'".createThumb($path)."'\" />";
    ?>
    (that's in a while statement)

    i get a page full of wingdings and it says i'm also missing an argument. can anyone help?? the directions with this script really suck and don't explain anything.

    thanks,
    sammy

  2. #2
    Join Date
    May 2007
    Location
    Sweden
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post

    Hi there!

    Try this:
    PHP Code:
        function createThumb($source)
        {
        
    $thumb_size 150;
        
    $size getimagesize($source);
        
    $width $size[0];
        
    $height $size[1];

            if(
    $width $height)
            {
            
    $x ceil( ( $width $height ) / );
            
    $width $height;
            }
            elseif(
    $height $width)
            {
            
    $y ceil( ( $height $width ) / );
            
    $height $width;
            }

        
    $new_im ImageCreatetruecolor($thumb_size,$thumb_size);
        
    $im imagecreatefromjpeg($source);
        
    imagecopyresampled($new_im$im00$x$y$thumb_size$thumb_size$width$height);
        
    imagejpeg($new_im''100);
        } 
    Make sure it's a JPEG-image you send, else you also must use imagegif() and imagepng etc.

    Hopes this was usefull info!

    ----------------------------------
    Edit:
    ----------------------------------
    I forgoted, you can never call the createThumb()-function in a img-tag directly. You must add the the function in a own file let's say thumbnail.php,

    Thumbnail.php:
    PHP Code:
    <?php
        
    function createThumb($source)
        {
        
    $thumb_size 150;
        
    $size getimagesize($source);
        
    $width $size[0];
        
    $height $size[1];

            if(
    $width $height)
            {
            
    $x ceil( ( $width $height ) / );
            
    $width $height;
            }
            elseif(
    $height $width)
            {
            
    $y ceil( ( $height $width ) / );
            
    $height $width;
            }

        
    $new_im ImageCreatetruecolor($thumb_size,$thumb_size);
        
    $im imagecreatefromjpeg($source);
        
    imagecopyresampled($new_im$im00$x$y$thumb_size$thumb_size$width$height);
        
    imagejpeg($new_im''100);
        }


    $path "upload/$pic1";

    createThumb($path);
    ?>
    Then you have the page where youre image-tag call the thumbnail.ph, let's say it's name is getImage.php,

    getImage.php
    PHP Code:
    <html>
    <
    head>
    <
    title>Get image</title>
    </
    head>

    <
    body>
    <
    img src="thumbnail.php">
    </
    body>

    </
    html
    I hopes you understand how I mean!



    Best regards,
    mbrodin
    Last edited by mbrodin; 05-30-2007 at 07:37 AM. Reason: Added more info ...

  3. #3
    Join Date
    Jan 2007
    Posts
    94
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    awesome! you answered my next question too about pngs and gifs.... ROCK ON! THANK YOU!

  4. #4
    Join Date
    May 2007
    Location
    Sweden
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post

    Quote Originally Posted by jnscollier View Post
    awesome! you answered my next question too about pngs and gifs.... ROCK ON! THANK YOU!
    It's always a plessure to help!

    Best regards,
    mbrodin

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •