Re: PDF Thumbnails

From: Date: Thu, 29 Sep 2005 19:58:25 +0000
Subject: Re: PDF Thumbnails
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-223426@lists.php.net to get a copy of this message
I wrote a script for this; it's designed to run from the command line in *nix, but can be triggered via exec(): Usage: ./pdf2thumb.php "source_dir" "out_dir" [code] #!/usr/local/bin/php <? function getDirFiles($dirPath){ $filesArr=array(""); if ($handle = opendir($dirPath)){
       while (false !== ($file = readdir($handle)))
           if ($file != "." && $file != ".."){$filesArr[] = trim($file);}
           closedir($handle);}
return $filesArr; } function usage(){ echo("USAGE: pdf2thumb source_folder_path <destination_folder_path>\n\n"); exit; } if(!isset($argv[1])){usage();} substr($argv[1],-1)=="/"?$path=$argv[1]:$path=$argv[1]."/"; isset($argv[2])?$dest_path=$argv[2]:$dest_path=$path; substr($dest_path,-1)=="/"?$dest_path=$dest_path:$dest_path.="/"; $total_time=0; $total_files=0; if(!file_exists($dest_path)){mkdir $dest_path;} $files=getDirFiles($path); for($i=0;$i<count($files);$i++){ if(substr($files[$i],-3)=="pdf"){
       echo("Converting ".$files[$i]."... ");
       $time_start = microtime(true);
       $old_name=$path.$files[$i];
       $new_name=$dest_path.str_replace(".pdf",".jpg",$files[$i]);
       /usr/bin/convert '$old_name' -thumbnail 240x160 '$new_name';
       $time_end = microtime(true);
       $convert_time=round($time_end-$time_start,2);
       echo("Done. ($convert_time seconds)\n");
       $total_time+=$convert_time;
       $total_files++;
} } echo("\n---------------------------------------------------\n"); echo("$total_files files converted in ".round($total_time/60,2)." $minutes (AVG: ".round($total_time/$total_files,2)."s)\n\n"); ?> [/code] benc11@gmail.com wrote:
You would haven't happen to have an example? I am new to imagemagick. Any help would be greatly appreciated. On 9/26/05, Jim Moseby <JMoseby@nrbindustries.com> wrote:
-----Original Message----- From: benc11@gmail.com [mailto:benc11@gmail.com] Sent: Monday, September 26, 2005 1:43 AM To: php-general@lists.php.net Subject: [PHP] PDF Thumbnails I give my users an option to upload pdf files to my site and would like them to see a thumbnail view of the file once uploaded. Has anyone heard of a way how to do this?
     
The 'convert' function of ImageMagick will do it. JM


« previous php.general (#223426) next »