initial commit
This commit is contained in:
50
PHP_Scripts/extract_pdf/extract.php
Normal file
50
PHP_Scripts/extract_pdf/extract.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/* This file is meant to run from the CLI/Shell
|
||||
* it extracts the first page of a pdf file and saves to
|
||||
* jpg with same name + _thumb pic being 240pix wide
|
||||
* Author Carsten Jensen aka Tomse @ http://awesome.commodore.me
|
||||
* Copyright (C) 2012 Carsten Jensen
|
||||
* This is distributed under GNU GPLv2
|
||||
*/
|
||||
|
||||
/* Requirements:
|
||||
* php (cli/shell version) / or as apache site
|
||||
* imagemagick module
|
||||
*/
|
||||
|
||||
/* Usage:
|
||||
* Run the file from the browser (apache setup)
|
||||
* or from cli : php -f extract
|
||||
* thumb files will be saved in same dir as pdf files
|
||||
*/
|
||||
|
||||
// Edit the path here where your PDF files are stored.
|
||||
$dir = "./pages/";
|
||||
// Edit width in pixels to change sizes
|
||||
$size = 240;
|
||||
|
||||
// Replace false with true to make the script work
|
||||
$work = false;
|
||||
|
||||
|
||||
// code is here.. nothing more to modify
|
||||
// -------------------------------------
|
||||
if ($work == true)
|
||||
{
|
||||
$files = glob($dir . "*.[pP][dD][fF]");
|
||||
foreach($files as $v)
|
||||
{
|
||||
$filename = substr($v, 0, strlen($v) - 4);
|
||||
$thumb = new Imagick();
|
||||
$thumb->setResolution(300, 300);
|
||||
$thumb->readImage($v ."[0]");
|
||||
$thumb->setImageFormat('jpeg');
|
||||
$thumb->setImagecompression(imagick::COMPRESSION_JPEG);
|
||||
$thumb->setImageCompressionQuality(75);
|
||||
$thumb->resizeImage($size, 1024, imagick::FILTER_LANCZOS, 1, true);
|
||||
$thumb->writeImage($filename . "_thumb.jpg");
|
||||
$thumb->clear();
|
||||
$thumb->destroy();
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user