Open Sencillo  2015.107
Long live the simplicity of PHP
 All Data Structures Namespaces Functions Pages
imagick.convert.pdf2jpg.php
1 <?php
11 class PDFtoJPG
12 {
13  public $error=array();
14  public $path=array();
15  private $j;
16 
27  public function convert($name,$id=null,$pdfSource=null,$jpgOutDir=null,$quality=null)
28  {
29  ignore_user_abort(true);
30  $id = ($id === null ? 'Guests' : $id);
31  $pdfSource = ($pdfSource === null ? './' : $pdfSource);
32  $jpgOutDir = ($jpgOutDir === null ? './' : $jpgOutDir);
33  $quality = ($quality === null ? 100 : $quality);
34 
35  $imagick = new Imagick();
36  chmod($pdfSource,0777);
37  chmod($jpgOutDir,0777);
38  //rmdir($jpgOutDir."/user$id");
39  mkdir($jpgOutDir."/user$id",0777);
40  rmdir($jpgOutDir."/user$id/$name");
41  mkdir($jpgOutDir."/user$id/$name",0777);
42  chmod($jpgOutDir."/user$id/",0777);
43  chmod($jpgOutDir."/user$id/$name/",0777);
44 
45  $i=0;
46  $this->j=1;
47  while($i<1000)
48  {
49  $this->outPath($jpgOutDir."/user".$id."/".$name."/".$name."[".$i."].jpg");
50  try
51  {
52  $imagick->setResolution(144,144);
53  $imagick->readImage($this->inPath($pdfSource."/user".$id."/".$name."[".$i."]"));
54  //$imagick->setCompression(Imagick::COMPRESSION_JPEG);
55  $imagick->setImageCompressionQuality($quality);
56  //$resolution=$imagick->getImageResolution();
57  //$imagick->scaleImage(0,1000);
58 
59  //$imagick->setImageDepth(600);
60  $imagick->writeImage($this->outPath($jpgOutDir."/user".$id."/".$name."/".$name."[".$i."].jpg"));
61  $this->j++;
62  }
63  catch(Exception $e)
64  {
65  $this->error[$i] = $e;
66  $this->error['message'] = 'Imagick Exception: '.$e;
67  break;
68  }
69  $i++;
70  }
71  return $this->j;
72  }
73 
83  public function simulation($name,$id=null,$pdfSource=null)
84  {
85  $id = ($id === null ? 'Guests' : $id);
86  $pdfSource = ($pdfSource === null ? './' : $pdfSource);
87 
88  $imagick = new Imagick();
89 
90  $i=0;
91  $this->j=1;
92  while($i<1000)
93  {
94  try
95  {
96  $imagick->readImage($this->inPath($pdfSource."/user".$id."/".$name."[".$i."]"));
97  $this->j++;
98  }
99  catch(Exception $e)
100  {
101  break;
102  }
103  $i++;
104  }
105  return array('maxPage'=>$this->j,
106  'minPage'=>0,
107  'source'=>$pdfSource."/user".$id."/".$name);
108  }
109 
120  public function pdfPathGenerator($name,$id=null,$pdfSource=null)
121  {
122  $id = ($id === null ? 'Guests' : $id);
123  $pdfSource = ($pdfSource === null ? './' : $pdfSource);
124 
125  return array('maxPage'=>'unknown',
126  'minPage'=>'unknown',
127  'source'=>$pdfSource."/user".$id."/".$name);
128  }
132  public function errorList()
133  {
134  return $this->error;
135  }
136 
141  public function inPath($path)
142  {
143  $this->path['in'] = $path;
144  return $path;
145  }
146 
151  public function outPath($path)
152  {
153  $this->path['out'] = $path;
154  return $path;
155  }
156 }
157 ?>
simulation($name, $id=null, $pdfSource=null)
convert($name, $id=null, $pdfSource=null, $jpgOutDir=null, $quality=null)
pdfPathGenerator($name, $id=null, $pdfSource=null)