PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, October 11, 2022

[FIXED] how to automatically copy an entire directory as thumbnails using phpthumb (or some other library)

 October 11, 2022     gd, php, phpthumb, thumbnails     No comments   

Issue

I would like all images dropped in a directory to be copied into a separate directory as thumbnails that i can then view on my site. Right now i'm researching phpthumb, but have also downloaded wideimage and zen photo.

Thanks if you can find an exact duplicate to this, near matches may also be helpful.

Here is the script that only copies a single files:

require_once '../ThumbLib.inc.php';
//include the thumb library 
$thumb = PhpThumbFactory::create('test.jpg');
//create a new image from the targeted jpegs
$thumb->adaptiveResize(100, 100);
//resize 
$thumb->save('test.png', 'png');
//save as 'test' with the file type png
//echo "<img src='$thumb' class='thumb'>";
$thumb->show();
//print the thumbnail to the screen

Solution

Try

$dir = "photos" ;
$destination = "thumb" ;
$images = scandir($dir);

foreach ( $images as $image ) {

    if(is_file($image))
    {
        $ext = pathinfo ( $dir . DIRECTORY_SEPARATOR . $image, PATHINFO_EXTENSION );
        $thumb = PhpThumbFactory::create ( $dir . DIRECTORY_SEPARATOR . $image );
        $thumb->adaptiveResize ( 100, 100 );
        $thumb->save ( $destination . DIRECTORY_SEPARATOR . $image, $ext );
        $thumb->show ();
    }
}


Answered By - Baba
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing