How do I implement using your script? Do this take all of the files in a
directory and convert them into pdf thumbnails? Where does the directory
path go? Thanks for posting and the help.
 On 9/29/05, Matt Darby <[EMAIL PROTECTED]> wrote:
>
> 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]
>
> [EMAIL PROTECTED] 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 <[EMAIL PROTECTED]> wrote:
> >
> >
> >>>-----Original Message-----
> >>>From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> >>>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
> >>
> >>
> >>
> >
> >
> >
>
>
>

Reply via email to