$pdfmark .= '[ /Subtype /Highlight /Rect [ ' . $bottomx . ' ' . $bottomy . ' ' . $topx . ' ' . $topy . ' ] /QuadPoints [ ' . $bottomx . ' ' . $topy . ' ' . $topx . ' ' . $topy . ' ' . $bottomx . ' ' . $bottomy . ' ' . $topx . ' ' . $bottomy . ' ] /SrcPg ' . $annotations['page'] . ' /Color [0.78 0.8 1] /ANN pdfmark' . PHP_EOL; } $result = null; if (!empty($notetxt)) { file_put_contents($temp_dir . DIRECTORY_SEPARATOR . 'lib_' . session_id() . DIRECTORY_SEPARATOR . 'annotations.txt', $notetxt); $supfile_arr[] = $temp_dir . DIRECTORY_SEPARATOR . 'lib_' . session_id() . DIRECTORY_SEPARATOR . 'annotations.txt'; } if (!empty($pdfmark)) { file_put_contents($temp_dir . DIRECTORY_SEPARATOR . 'lib_' . session_id() . DIRECTORY_SEPARATOR . 'pdfmark.txt', $pdfmark); $temp_file = $temp_dir . DIRECTORY_SEPARATOR . 'lib_' . session_id() . DIRECTORY_SEPARATOR . $file . '-annotated.pdf'; exec(select_ghostscript() . ' -o "' . $temp_file . '" -dPDFSETTINGS=/prepress -sDEVICE=pdfwrite "' . $file_name . '" "' . $temp_dir . DIRECTORY_SEPARATOR . 'lib_' . session_id() . DIRECTORY_SEPARATOR . 'pdfmark.txt"', $out); $file_name = $temp_file; } } //ATTACH RICH-TEXT NOTES if (in_array('richnotes', $_GET['attachments'])) { database_connect($database_path, 'library'); $userid = $dbHandle->quote($_SESSION['user_id']); $qfile = $dbHandle->quote($_GET['file']); $result = $dbHandle->query("SELECT notes FROM notes\n WHERE fileID=(SELECT id FROM library WHERE file={$qfile})\n AND userID={$userid} LIMIT 1"); $notetxt = ''; $notetxt = $result->fetchColumn(); if (!empty($notetxt)) { $notetxt = '<!DOCTYPE html><html style="width:100%;height:100%"><head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>I, Librarian - 2.4 Notes</title></head><body>' . $notetxt . '</body></html>';
} // send image size to js $img_size_array = getimagesize('library' . DIRECTORY_SEPARATOR . 'pngs' . DIRECTORY_SEPARATOR . $file . "." . $page . ".png"); print json_encode(array_slice($img_size_array, 0, 2)); } else { die('Error! Conversion with Ghostscript failed.'); } } else { die('PDF does not exist.'); } die; } if (isset($_GET['renderthumbs'])) { if (file_exists($pdf_path . DIRECTORY_SEPARATOR . $file)) { if (!file_exists($png_path . DIRECTORY_SEPARATOR . $file . ".t1.png") || filemtime($png_path . DIRECTORY_SEPARATOR . $file . '.t1.png') < filemtime($pdf_path . DIRECTORY_SEPARATOR . $file)) { exec(select_ghostscript() . " -dSAFER -sDEVICE=png256 -r20 -dTextAlphaBits=1 -dGraphicsAlphaBits=1 -o \"" . $png_path . DIRECTORY_SEPARATOR . $file . ".t%d.png\" \"" . $pdf_path . DIRECTORY_SEPARATOR . $file . "\""); } } die; } if (isset($_GET['renderbookmarks'])) { if (file_exists($pdf_path . DIRECTORY_SEPARATOR . $file)) { $safe_file_name = preg_replace('/[^\\d\\.pdf]/', '', $_GET['file']); $file_name = $pdf_path . DIRECTORY_SEPARATOR . $safe_file_name; $temp_file = $temp_dir . DIRECTORY_SEPARATOR . $safe_file_name . '-bookmarks.txt'; if (!file_exists($temp_file) || filemtime($temp_file) < filemtime($file_name)) { system(select_pdftk() . '"' . $file_name . '" dump_data output "' . $temp_file . '"', $ret); } if (file_exists($temp_file)) { $i = 0; $bookmark = array();
public function downloadPDF($mode = null, $attachments = array()) { // Add watermarks. if (!empty($_SESSION['watermarks'])) { if ($_SESSION['watermarks'] == 'nocopy') { $watermark = 'nocopy'; $message = str_repeat('DO NOT COPY ', 5); } elseif ($_SESSION['watermarks'] == 'confidential') { $watermark = 'confidential'; $message = str_repeat('CONFIDENTIAL ', 5); } $pdfmark = '<<' . ' /EndPage' . ' {' . ' 2 eq { pop false }' . ' {' . ' gsave' . ' /Helvetica_Bold 30 selectfont' . ' 1 0 0 setrgbcolor 10 5 moveto (' . $message . ') show' . ' grestore' . ' true' . ' } ifelse' . ' } bind' . ' >> setpagedevice'; $pdfmark_file = $this->temp_path . DIRECTORY_SEPARATOR . 'lib_' . session_id() . DIRECTORY_SEPARATOR . $watermark . '.ps'; file_put_contents($pdfmark_file, $pdfmark); $temp_file = $this->temp_path . DIRECTORY_SEPARATOR . $this->file_name . $watermark . '.pdf'; exec(select_ghostscript() . ' -o "' . $temp_file . '" -dPDFSETTINGS=/prepress -sDEVICE=pdfwrite "' . $pdfmark_file . '" "' . $this->pdf_full_path . '"'); $this->pdf_full_path = $temp_file; } // Attach PDF annotations. if (isset($attachments) && in_array('notes', $attachments)) { // Get page sizes. $pages = $this->getPageInfo(); $page_sizes = $pages['page_sizes']; $dbHandle = database_connect($this->database_path, 'library'); $user_id_q = $dbHandle->quote($_SESSION['user_id']); $user_name_q = $dbHandle->quote($_SESSION['user']); $file_name_q = $dbHandle->quote($this->file_name); // Attach from all users. if (in_array('allusers', $attachments)) { $quoted_path = $dbHandle->quote($this->database_path . DIRECTORY_SEPARATOR . 'users.sq3'); $dbHandle->exec("ATTACH DATABASE {$quoted_path} AS userdatabase"); $result = $dbHandle->query("SELECT id,annotation,page,top,left,userdatabase.users.username AS username FROM annotations\n JOIN userdatabase.users ON userdatabase.users.userID=annotations.userID\n WHERE filename={$file_name_q}\n ORDER BY CAST(page AS INTEGER) ASC, CAST(top AS INTEGER) ASC"); $dbHandle->exec("DETACH DATABASE userdatabase"); } else { // Attach from this user. $result = $dbHandle->query("SELECT id,annotation,page,top,left," . $user_name_q . " AS username FROM annotations\n WHERE filename={$file_name_q}\n AND userID={$user_id_q}\n ORDER BY CAST(page AS INTEGER) ASC, CAST(top AS INTEGER) ASC"); } $pdfmark = ''; while ($annotations = $result->fetch(PDO::FETCH_NAMED)) { // Calculate width and height in points for each page. $w = round($page_sizes[$annotations['page'] + 1][0] * 72 / $this->page_resolution); $h = round($page_sizes[$annotations['page'] + 1][1] * 72 / $this->page_resolution); $bottomx = round($w * ($annotations['left'] / 100)); $bottomy = round($h * (1 - $annotations['top'] / 100) - 20); $annotation = strtoupper(bin2hex(iconv('UTF-8', 'UCS-2BE', $annotations['annotation']))); $pdfmark .= '[ /Contents <FEFF' . $annotation . '> /Rect [' . $bottomx . ' ' . $bottomy . ' ' . (20 + $bottomx) . ' ' . (20 + $bottomy) . '] /Subtype /Text /Name /Comment /SrcPg ' . $annotations['page'] . ' /Open false /Title (Comment #' . $annotations['id'] . ' by ' . $annotations['username'] . ') /Color [0.6 0.65 0.9] /ANN pdfmark' . PHP_EOL; } $result = null; // Attach highlights. if (in_array('allusers', $attachments)) { // Attach from all users $quoted_path = $dbHandle->quote($this->database_path . DIRECTORY_SEPARATOR . 'users.sq3'); $dbHandle->exec("ATTACH DATABASE {$quoted_path} AS userdatabase"); $result = $dbHandle->query("SELECT id,page,top,left,width,userdatabase.users.username AS username FROM yellowmarkers\n JOIN userdatabase.users ON userdatabase.users.userID=yellowmarkers.userID\n WHERE filename=" . $file_name_q); $dbHandle->exec("DETACH DATABASE userdatabase"); } else { // Attach from this user. $result = $dbHandle->query("SELECT id,page,top,left,width," . $user_name_q . " AS username FROM yellowmarkers\n WHERE filename={$file_name_q}\n AND userID={$user_id_q}"); } // Compile Pdfmark for highlights. while ($annotations = $result->fetch(PDO::FETCH_NAMED)) { // Calculate width and height in points for each page. $w = round($page_sizes[$annotations['page'] + 1][0] * 72 / $this->page_resolution); $h = round($page_sizes[$annotations['page'] + 1][1] * 72 / $this->page_resolution); $bottomx = round($w * ($annotations['left'] / 100)); $bottomy = round($h * (1 - $annotations['top'] / 100) - 0.012 * $h); $topx = round($w * ($annotations['left'] / 100) + $annotations['width'] / 100 * $w); $topy = round($h * (1 - $annotations['top'] / 100)); $pdfmark .= '[ /Subtype /Highlight /Rect [ ' . $bottomx . ' ' . $bottomy . ' ' . $topx . ' ' . $topy . ' ] /QuadPoints [ ' . $bottomx . ' ' . $topy . ' ' . $topx . ' ' . $topy . ' ' . $bottomx . ' ' . $bottomy . ' ' . $topx . ' ' . $bottomy . ' ] /SrcPg ' . $annotations['page'] . ' /Color [0.78 0.8 1] /Title (Highlight by ' . $annotations['username'] . ') /ANN pdfmark' . PHP_EOL; } $result = null; // Write all annotations to the PDF. if (!empty($pdfmark)) { $pdfmark_file = $this->temp_path . DIRECTORY_SEPARATOR . 'lib_' . session_id() . DIRECTORY_SEPARATOR . 'pdfmark.txt'; file_put_contents($pdfmark_file, $pdfmark); $temp_file = $this->temp_path . DIRECTORY_SEPARATOR . 'lib_' . session_id() . DIRECTORY_SEPARATOR . $this->file_name . '-annotated.pdf'; exec(select_ghostscript() . ' -o "' . $temp_file . '" -dPDFSETTINGS=/prepress -sDEVICE=pdfwrite "' . $this->pdf_full_path . '" "' . $pdfmark_file . '"'); $this->pdf_full_path = $temp_file; } } // Attach files. $supfile_arr = array(); // Attach rich-text notes. if (isset($attachments) && in_array('richnotes', $attachments)) { $dbHandle = database_connect($this->database_path, 'library'); $user_id_q = $dbHandle->quote($_SESSION['user_id']); $file_name_q = $dbHandle->quote($this->file_name); $result = $dbHandle->query("SELECT notes FROM notes\n WHERE fileID=(SELECT id FROM library WHERE file={$file_name_q})\n AND userID={$user_id_q}"); $notetxt = $result->fetchColumn(); if (!empty($notetxt)) { $notetxt = '<!DOCTYPE html><html style="width:100%;height:100%"><head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>I, Librarian - Notes</title></head><body>' . $notetxt . '</body></html>'; file_put_contents($this->temp_path . DIRECTORY_SEPARATOR . 'lib_' . session_id() . DIRECTORY_SEPARATOR . 'richnotes.html', $notetxt); $supfile_arr[] = $this->temp_path . DIRECTORY_SEPARATOR . 'lib_' . session_id() . DIRECTORY_SEPARATOR . 'richnotes.html'; } } // Attach supplementary files. if (isset($attachments) && in_array('supp', $attachments)) { $supfiles = array(); $integer = substr($this->file_name, 0, strpos($this->file_name, '.')); $supfiles = glob($this->supplement_path . DIRECTORY_SEPARATOR . get_subfolder($integer) . DIRECTORY_SEPARATOR . $integer . '*'); $supfile_arr = array_merge((array) $supfiles, $supfile_arr); } // Ghostscript can attach files to PDF, but let's do it with Zip. if (!empty($supfile_arr) && extension_loaded('zip')) { $temp_file = $this->temp_path . DIRECTORY_SEPARATOR . 'lib_' . session_id() . DIRECTORY_SEPARATOR . 'output.zip'; $zip = new ZipArchive(); $zip->open($temp_file, ZIPARCHIVE::OVERWRITE); // Add PDF. $zip->addFile($this->pdf_full_path, basename($this->file_name)); // Add supplementary files. foreach ($supfile_arr as $supfile) { $zip->addFile($supfile, basename($supfile)); } $zip->close(); $this->pdf_full_path = $temp_file; $this->file_name = $this->file_name . '.zip'; } ob_end_clean(); // Output finished PDF. if (!empty($supfile_arr) && extension_loaded('zip')) { header("Content-type: application/zip"); } else { header("Content-type: application/pdf"); } if (isset($mode) && $mode == 'download') { header("Content-Disposition: attachment; filename=\"{$this->file_name}\""); } else { header("Content-Disposition: inline"); } header("Pragma: no-cache"); header("Expires: 0"); header('Content-Length: ' . filesize($this->pdf_full_path)); readfile($this->pdf_full_path); }
<?php include_once 'data.php'; include_once 'functions.php'; session_write_close(); database_connect(IL_DATABASE_PATH, 'library'); $file_query = $dbHandle->quote(intval($_GET['file'])); $result = $dbHandle->query("SELECT file FROM library WHERE id={$file_query} LIMIT 1"); $file = $result->fetchColumn(); $dbHandle = null; if (is_file(IL_PDF_PATH . get_subfolder($file) . DIRECTORY_SEPARATOR . $file)) { exec(select_ghostscript() . ' -dSAFER -dBATCH -dNOPAUSE -sDEVICE=bmp16m -r300 -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -dDOINTERPOLATE -o "' . IL_TEMP_PATH . DIRECTORY_SEPARATOR . $file . '.%03d.bmp" "' . IL_PDF_PATH . DIRECTORY_SEPARATOR . get_subfolder($file) . DIRECTORY_SEPARATOR . $file . '"'); $file_arr = glob(IL_TEMP_PATH . DIRECTORY_SEPARATOR . '*.bmp'); if (is_array($file_arr)) { set_time_limit(600); for ($i = 0; $i < count($file_arr); $i++) { exec(select_tesseract() . ' "' . $file_arr[$i] . '" "' . IL_TEMP_PATH . DIRECTORY_SEPARATOR . $file . '.' . $i . '"'); if (is_file(IL_TEMP_PATH . DIRECTORY_SEPARATOR . $file . '.' . $i . '.txt')) { file_put_contents(IL_TEMP_PATH . DIRECTORY_SEPARATOR . $file . 'final.txt', file_get_contents(IL_TEMP_PATH . DIRECTORY_SEPARATOR . $file . '.' . $i . '.txt'), FILE_APPEND); unlink(IL_TEMP_PATH . DIRECTORY_SEPARATOR . $file . '.' . $i . '.txt'); unlink($file_arr[$i]); } else { die('OCR software not functional.'); } } $string = file_get_contents(IL_TEMP_PATH . DIRECTORY_SEPARATOR . $file . 'final.txt'); unlink(IL_TEMP_PATH . DIRECTORY_SEPARATOR . $file . 'final.txt'); $string = preg_replace('/[^\\x{0009}\\x{000a}\\x{000d}\\x{0020}-\\x{D7FF}\\x{E000}-\\x{FFFD}]+/u', ' ', $string); $string = trim($string); if (!empty($string)) { $order = array("\r\n", "\n", "\r");
exec(select_pdfinfo() . ' test.pdf', $output); if (!empty($output)) { die('OK'); } else { die; } } elseif ($_GET['binary'] == 'pdftohtml') { exec(select_pdftohtml() . ' -q -noframes -enc UTF-8 -nomerge -c -xml test.pdf "' . $temp_dir . DIRECTORY_SEPARATOR . 'test"'); if (file_exists($temp_dir . DIRECTORY_SEPARATOR . 'test.xml')) { unlink($temp_dir . DIRECTORY_SEPARATOR . 'test.xml'); die('OK'); } else { die; } } elseif ($_GET['binary'] == 'ghostscript') { exec(select_ghostscript() . ' -sDEVICE=png16m -r15 -dTextAlphaBits=1 -dGraphicsAlphaBits=1 -dFirstPage=1 -dLastPage=1 -o "' . $temp_dir . DIRECTORY_SEPARATOR . 'test.png" test.pdf'); if (file_exists($temp_dir . DIRECTORY_SEPARATOR . 'test.png')) { unlink($temp_dir . DIRECTORY_SEPARATOR . 'test.png'); die('OK'); } else { die; } } elseif ($_GET['binary'] == 'pdftk') { exec(select_pdftk() . 'test.pdf dump_data output "' . $temp_dir . DIRECTORY_SEPARATOR . 'test-pdftk.txt"'); if (is_readable($temp_dir . DIRECTORY_SEPARATOR . 'test-pdftk.txt') && filesize($temp_dir . DIRECTORY_SEPARATOR . 'test-pdftk.txt') > 0) { unlink($temp_dir . DIRECTORY_SEPARATOR . 'test-pdftk.txt'); die('OK'); } else { die; } } elseif ($_GET['binary'] == 'tesseract') {
<?php include_once 'data.php'; include_once 'functions.php'; session_write_close(); ini_set('max_execution_time', 600); database_connect($database_path, 'library'); $file_query = $dbHandle->quote(intval($_GET['file'])); $result = $dbHandle->query("SELECT file FROM library WHERE id={$file_query} LIMIT 1"); $file = $result->fetchColumn(); $dbHandle = null; if (is_file($library_path . $file)) { exec(select_ghostscript() . ' -dSAFER -dBATCH -dNOPAUSE -sDEVICE=bmp16m -r300 -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -dDOINTERPOLATE -o "' . $temp_dir . DIRECTORY_SEPARATOR . $file . '.%03d.bmp" "' . $library_path . $file . '"'); $file_arr = glob($temp_dir . DIRECTORY_SEPARATOR . '*.bmp'); if (is_array($file_arr)) { for ($i = 0; $i < count($file_arr); $i++) { exec('tesseract "' . $file_arr[$i] . '" "' . $temp_dir . DIRECTORY_SEPARATOR . $file . '.' . $i . '"'); if (is_file($temp_dir . DIRECTORY_SEPARATOR . $file . '.' . $i . '.txt')) { file_put_contents($temp_dir . DIRECTORY_SEPARATOR . $file . 'final.txt', file_get_contents($temp_dir . DIRECTORY_SEPARATOR . $file . '.' . $i . '.txt'), FILE_APPEND); unlink($temp_dir . DIRECTORY_SEPARATOR . $file . '.' . $i . '.txt'); unlink($file_arr[$i]); } else { die('OCR software not functional.'); } } $stopwords = "a's, able, about, above, according, accordingly, across, actually, after, afterwards, again, against, ain't, all, allow, allows, almost, alone, along, already, also, although, always, am, among, amongst, an, and, another, any, anybody, anyhow, anyone, anything, anyway, anyways, anywhere, apart, appear, appreciate, appropriate, are, aren't, around, as, aside, ask, asking, associated, at, available, away, awfully, be, became, because, become, becomes, becoming, been, before, beforehand, behind, being, believe, below, beside, besides, best, better, between, beyond, both, brief, but, by, c'mon, c's, came, can, can't, cannot, cant, cause, causes, certain, certainly, changes, clearly, co, com, come, comes, concerning, consequently, consider, considering, contain, containing, contains, corresponding, could, couldn't, currently, definitely, described, despite, did, didn't, different, do, does, doesn't, doing, don't, done, down, during, each, edu, eg, either, else, elsewhere, enough, entirely, especially, et, etc, even, ever, every, everybody, everyone, everything, everywhere, ex, exactly, example, except, far, few, followed, following, follows, for, former, formerly, from, further, furthermore, get, gets, getting, given, gives, go, goes, going, gone, got, gotten, greetings, had, hadn't, happens, hardly, has, hasn't, have, haven't, having, he, he's, hello, help, hence, her, here, here's, hereafter, hereby, herein, hereupon, hers, herself, hi, him, himself, his, hither, hopefully, how, howbeit, however, i'd, i'll, i'm, i've, ie, if, in, inasmuch, inc, indeed, indicate, indicated, indicates, inner, insofar, instead, into, inward, is, isn't, it, it'd, it'll, it's, its, itself, just, keep, keeps, kept, know, knows, known, last, lately, later, latter, latterly, least, less, lest, let, let's, like, liked, likely, little, look, looking, looks, ltd, mainly, many, may, maybe, me, mean, meanwhile, merely, might, more, moreover, most, mostly, much, must, my, myself, name, namely, nd, near, nearly, necessary, need, needs, neither, never, nevertheless, new, next, no, nobody, non, none, noone, nor, normally, not, nothing, novel, now, nowhere, obviously, of, off, often, oh, ok, okay, old, on, once, ones, only, onto, or, other, others, otherwise, ought, our, ours, ourselves, out, outside, over, overall, own, particular, particularly, per, perhaps, placed, please, possible, presumably, probably, provides, que, quite, qv, rather, rd, re, really, reasonably, regarding, regardless, regards, relatively, respectively, right, said, same, saw, say, saying, says, secondly, see, seeing, seem, seemed, seeming, seems, seen, self, selves, sensible, sent, serious, seriously, several, shall, she, should, shouldn't, since, so, some, somebody, somehow, someone, something, sometime, sometimes, somewhat, somewhere, soon, sorry, specified, specify, specifying, still, sub, such, sup, sure, t's, take, taken, tell, tends, th, than, thank, thanks, thanx, that, that's, thats, the, their, theirs, them, themselves, then, thence, there, there's, thereafter, thereby, therefore, therein, theres, thereupon, these, they, they'd, they'll, they're, they've, think, this, thorough, thoroughly, those, though, through, throughout, thru, thus, to, together, too, took, toward, towards, tried, tries, truly, try, trying, twice, un, under, unfortunately, unless, unlikely, until, unto, up, upon, us, use, used, useful, uses, using, usually, value, various, very, via, viz, vs, want, wants, was, wasn't, way, we, we'd, we'll, we're, we've, welcome, well, went, were, weren't, what, what's, whatever, when, whence, whenever, where, where's, whereafter, whereas, whereby, wherein, whereupon, wherever, whether, which, while, whither, who, who's, whoever, whole, whom, whose, why, will, willing, wish, with, within, without, won't, wonder, would, would, wouldn't, yes, yet, you, you'd, you'll, you're, you've, your, yours, yourself, yourselves"; $stopwords = explode(', ', $stopwords); $string = file_get_contents($temp_dir . DIRECTORY_SEPARATOR . $file . 'final.txt'); unlink($temp_dir . DIRECTORY_SEPARATOR . $file . 'final.txt'); $string = preg_replace('/[^\\x{0009}\\x{000a}\\x{000d}\\x{0020}-\\x{D7FF}\\x{E000}-\\x{FFFD}]+/u', ' ', $string); $string = trim($string);
header("Cache-Control: max-age={$seconds_to_cache}"); header("Cache-Control: private"); header('Last-Modified: ' . gmdate(DATE_RFC1123, filemtime($pdf_path . DIRECTORY_SEPARATOR . $file))); // Content type header('Content-Type: image/png'); header("Content-Disposition: inline"); // Output from cache if (is_readable($icon) && filemtime($pdf_path . DIRECTORY_SEPARATOR . $file) < filemtime($icon)) { ob_clean(); flush(); readfile($icon); die; } // Make big PNG if not found if (!is_readable($png) || filemtime($png_path . DIRECTORY_SEPARATOR . $file . '.1.png') < filemtime($pdf_path . DIRECTORY_SEPARATOR . $file)) { exec(select_ghostscript() . " -dSAFER -sDEVICE=png16m -r150 -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -dDOINTERPOLATE -dFirstPage=1 -dLastPage=1 -o \"" . $png_path . DIRECTORY_SEPARATOR . $file . ".1.png\" \"" . $pdf_path . DIRECTORY_SEPARATOR . $file . "\""); } // Icon dimensions $new_width = 360; $new_height = 240; if (!is_readable($png)) { // Error! Ghostscript DOES NOT WORK $image_p = @imagecreate($new_width, $new_height); $background_color = imagecolorallocate($image_p, 255, 255, 255); $text_color = imagecolorallocate($image_p, 255, 0, 0); imagestring($image_p, 3, 20, 20, "Error! Program Ghostscript not functional.", $text_color); } else { // Resample list($width, $height) = getimagesize($png); $image_p = imagecreatetruecolor($new_width, $new_height); $image = imagecreatefrompng($png);