Web Analytics Made Easy -
StatCounter my thumbnails are black - CodingForum

Announcement

Collapse
No announcement yet.

my thumbnails are black

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • my thumbnails are black

    The code below is mean to create thumbs for all images in a folder
    however they just come out black. Is there an arror or is it a gd function that isnt supported with gd 2.0.28


    PHP Code:
    <?php 

    include("bmp.php");

    $imagefolder='.';
    $thumbsfolder='.';
    $pics=directory($imagefolder,"jpg,JPG,JPEG,jpeg,png,PNG,BMP,bmp");
    $pics=ditchtn($pics,"tn_");
    if (
    $pics[0]!="")
    {
        foreach (
    $pics as $p)
        {
            
    createthumb($p,"tn_".$p,150,150);
        }
    }

    /*
        Function ditchtn($arr,$thumbname)
        filters out thumbnails
    */
    function ditchtn($arr,$thumbname)
    {
        foreach (
    $arr as $item)
        {
            if (!
    preg_match("/^".$thumbname."/",$item)){$tmparr[]=$item;}
        }
        return 
    $tmparr;
    }

    /*
        Function createthumb($name,$filename,$new_w,$new_h)
        creates a resized image
        variables:
        $name        Original filename
        $filename    Filename of the resized image
        $new_w        width of resized image
        $new_h        height of resized image
    */    
    function createthumb($name,$filename,$new_w,$new_h)
    {
        
    $system=explode(".",$name);
        if (
    preg_match("/jpg|jpeg/",$system[1])){$src_img=imagecreatefromjpeg($name);}
        if (
    preg_match("/png/",$system[1])){$src_img=imagecreatefrompng($name);}
        if(
    preg_match("/bmp/",$system[1])){$src_img=imagecreatefrombmp($name);}
        
    $size=getimagesize($src_img);
        
    $old_x=$size[0];
        
    $old_y=$size[1];
        if (
    $old_x $old_y
        {
            
    $thumb_w=$new_w;
            
    $thumb_h=$old_y*($new_h/$old_x);
        }
        if (
    $old_x $old_y
        {
            
    $thumb_w=$old_x*($new_w/$old_y);
            
    $thumb_h=$new_h;
        }
        if (
    $old_x == $old_y
        {
            
    $thumb_w=$new_w;
            
    $thumb_h=$new_h;
        }
        
    $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
        
    imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); 
        if (
    preg_match("/png/",$system[1]))
        {
            
    imagepng($dst_img,$filename); 
        } else if (
    preg_match("/bmp/",$system[1])){
            
    imagebmp($dst_img,$filename); 
        }else {
            
    imagejpeg($dst_img,$filename);
        }
        
    imagedestroy($dst_img); 
        
    imagedestroy($src_img); 
    }

    /*
            Function directory($directory,$filters)
            reads the content of $directory, takes the files that apply to $filter 
            and returns an array of the filenames.
            You can specify which files to read, for example
            $files = directory(".","jpg,gif");
                    gets all jpg and gif files in this directory.
            $files = directory(".","all");
                    gets all files.
    */
    function directory($dir,$filters)
    {
        
    $handle=opendir($dir);
        
    $files=array();
        if (
    $filters == "all"){while(($file readdir($handle))!==false){$files[] = $file;}}
        if (
    $filters != "all")
        {
            
    $filters=explode(",",$filters);
            while ((
    $file readdir($handle))!==false)
            {
                for (
    $f=0;$f<sizeof($filters);$f++):
                    
    $system=explode(".",$file);
                    if (
    $system[1] == $filters[$f]){$files[] = $file;}
                endfor;
            }
        }
        
    closedir($handle);
        return 
    $files;
    }*/
    ?>
    This is the output to the phpinfo function call on the server

    Array ( [GD Version] => bundled (2.0.28 compatible) [FreeType Support] => 1 [FreeType Linkage] => with freetype [T1Lib Support] => [GIF Read Support] => 1 [GIF Create Support] => 1 [JPG Support] => 1 [PNG Support] => 1 [WBMP Support] => 1 [XBM Support] => 1 [JIS-mapped Japanese Font Support] => )
    You can not say you know how to do something, until you can teach it to someone else.

  • #2
    gd black thumbnails

    i'm finding a couple others with this same issue. xinha imageManager uses gd which is generating black thumbnails for images. have no idea what is going on there. have you had any luck tracking this down?

    it seems like noone is responding to these posts in general . . .

    Comment


    • #3
      A new thread with links back to all these ancient threads would have been a better way to go about it... that said, I had problems with black backgrounds but I found a way around it somehow-- don't remember how though

      Comment


      • #4
        ~thaaaaaanks~

        I'll post a new thread, this problem is really annoying. We've gone throught almost everything trying to figure it out....

        Comment


        • #5
          my guess is that it's not seeing these ...

          imagecreatefromjpg()
          imagecreatefrompng()

          If you know that you're only using jpegs,
          write another script that only uses jpegs and
          eliminate the bmp and png stuff.

          Comment

          Working...
          X