-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathindex.php
46 lines (40 loc) · 1.05 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
phpinfo();
function pdf2png($PDF,$filePath){
if(!extension_loaded('imagick')){
echo "load extension failed\n";
return false;
}
if(!file_exists($PDF)){
return false;
}
$IM = new imagick();
$IM->setResolution(120,120);
$IM->setCompressionQuality(100);
$IM->readImage($PDF);
$canvas = new Imagick();
$canvas->newImage($IM->getImageWidth(), $IM->getImageHeight() * $IM->getNumberImages(), 'white');
$canvas->setImageFormat('png');
$index = 0 ;
$x = 0;
$y = 0;
foreach ($IM as $Key => $Var){
$Var->setImageFormat('png');
$canvas->compositeImage($Var, $Var->getImageCompose(), $x, $y);
$y += $Var->getImageHeight();
/*
$Filename = $Path.'/'.$index++.'.png';
if($Var->writeImage($Filename) == true){
$Return[] = $Filename;
}
*/
}
return $canvas->writeImage($filePath);
}
$pdfPath = "/tmp/test/1.pdf";
$destPath = "/tmp/test/1.png";
if(false == pdf2png($pdfPath, $destPath))
echo "pdf2 png failed";
else
echo "pdf2 png success";
?>