ArchivedTools/PHP_Scripts/extract_pdf/extract.php

51 lines
1.3 KiB
PHP
Raw Normal View History

2023-12-21 00:31:35 +00:00
<?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();
}
}
?>