Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2007
    Location
    England
    Posts
    495
    Tokens
    0

    Default [PHP] GD Image Help

    Hey,


    I made this code, but it only echos one image and there is 7 images in that directory... but it only echos one image resized, how would I fix the code to echo all 7 one after the other??

    CODE:
    PHP Code:
    <?php 
    // Generates thumnail graphic 
    function doGD($path,$jpg) {    
        
    $jpgFile "$path/$jpg";
        
    $width 120
        list(
    $width_orig$height_orig) = getimagesize($jpgFile);
        
    $height = (int) (($width $width_orig) * $height_orig);
        
    $image_p imagecreatetruecolor($width$height);
        
    $image imagecreatefromjpeg($jpgFile);
        
    imagecopyresampled($image_p$image0000$width$height$width_orig$height_orig);
        
    imagejpeg($image_pnull60);
        
    imagedestroy($image_p);    
    }

    //define the path as relative
    $path "test/";

    //using the opendir function
    $dir_handle = @opendir($path) or die("Unable to open $path");

    //running the while loop
    while ($file readdir($dir_handle)) 
    {

    if(
    $file == "." || $file == ".."){
    $file "";
    }else{
    header('Content-type: image/jpeg');
    doGD("$path","$file");
    }

    }

    //closing the directory
    closedir($dir_handle);
    ?>

    Dan


  2. #2
    Join Date
    Jul 2008
    Location
    Leeds, UK
    Posts
    47
    Tokens
    0

    Default

    ImageJPG outputs the picture.
    What you'll have to do is have 2 files.

    doGD.php
    PHP Code:
    if(!$_REQUEST['path'] || !$_REQUEST['jpg']) exit();
    $jpgFile $_REQUEST['path']."/".$_REQUEST['jpg'];
    $width 120;
    list(
    $width_orig$height_orig) = getimagesize($jpgFile);
    $height = (int) (($width $width_orig) * $height_orig);
    $image_p imagecreatetruecolor($width$height);
    $image imagecreatefromjpeg($jpgFile);
    imagecopyresampled($image_p$image0000$width$height$width_orig$height_orig);
    header('Content-type: image/jpeg');
    imagejpeg($image_pnull60);
    imagedestroy($image_p); 
    Main Code
    PHP Code:
    //define the path as relative
    $path "test/";

    //using the opendir function
    $dir_handle = @opendir($path) or die("Unable to open $path");

    //running the while loop
    while ($file readdir($dir_handle)) 
    {
        if(
    $file != "." && $file != ".."){
           echo 
    "<img src=\"doGD.php?path=".$path."&jpg=".$file." />";
        }
    }
    //closing the directory
    closedir($dir_handle); 

  3. #3
    Join Date
    Jun 2007
    Location
    England
    Posts
    495
    Tokens
    0

    Default

    EDIT:

    Sorry the ticko was looking at the wrong file!!!

    I have tryed your script but its echoing 4 boxes with no images in them just like a page in a little box

    Dan
    Last edited by Luno1599; 20-10-2009 at 09:05 PM.


  4. #4
    Join Date
    Jun 2007
    Location
    England
    Posts
    495
    Tokens
    0

    Default

    FIXED Thanks for your help!


  5. #5
    Join Date
    Jun 2007
    Location
    England
    Posts
    495
    Tokens
    0

    Default

    Need some more, help!!

    How would I add this? I want to add a watermark to at a 45 degree angle

    PHP Code:
    $black imagecolorallocate($imgrdg000);

    // The text to draw
    $text 'Testing...';
    // Replace path by your own font path
    $font 'arial.ttf';

    // Add the text
    imagettftext($imgrdg2001020$black$font$text);

    // Using imagepng() results in clearer text compared with imagejpeg()
    imagejpeg($imgrdg);
    imagedestroy($imgrdg); 
    Dan


Posting Permissions

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