Php photo gallery TWG | JFUploader | TWG Flash upload | WFU | Forum https://www.tinywebgallery.com/forum/ |
|
save pdf file but doesn't show https://www.tinywebgallery.com/forum/viewtopic.php?f=1&t=3748 |
Page 1 of 1 |
Author: | pumin [ 17. Oct 2014, 19:09 ] |
Post subject: | save pdf file but doesn't show |
Hello, On fresh install, I create a folder under pictures folder, thensave couple jpg and pdf files in there. Only jpg shows up but not pdfs. Not sure what to do, please suggest. Best Regards, Pumin |
Author: | TinyWebGallery [ 20. Oct 2014, 09:54 ] |
Post subject: | Re: save pdf file but doesn't show |
Why should pdf show? You always need a preview image. Please check the howto for support of other file types. Best, Michael |
Author: | pumin [ 23. Oct 2014, 04:01 ] |
Post subject: | Re: save pdf file but doesn't show |
ah, I have to manually create thumbnail jpg for each pdf files. Hope you don't mind. If I will hack and add a function to auto-create first page of PDF to a preview JPG, and add to where TWG creates regular preview. function pdf2jpg () { xxx } at which file, should I should start to look? thanks Mike! |
Author: | TinyWebGallery [ 23. Oct 2014, 09:22 ] |
Post subject: | Re: save pdf file but doesn't show |
Maybe you want to add this to the administration as there is already a feature to generate thumbnails for videos. and the code to generate previews from pdfs is also already included in the uploader. This is done with image magick. Look for tfu_preview in admin/upload/tfu_helper... Best, Michael |
Author: | pumin [ 28. Oct 2014, 15:08 ] |
Post subject: | Re: save pdf file but doesn't show |
Hello Mike, This is my try to generate pdf thumbnail. Not sure if it breaks anything, but seems working so far. It creates jpg in same folder with uploaded pdf. 1. config.php --> $use_image_magic=true; 2. install imagemagick on server 3. edit code below Code: // tw_plugin.php
// put inside function twg_plugin_process_upload_file($dir, $filename, $image) // line 80 $offp = getExtension($image); if ('pdf' == $offp) { $pdfpreviewimage = substr($filename,0,-4).".jpg"; $command = "convert \"{$filename}[0]\" -colorspace RGB -geometry 120 \"{$pdfpreviewimage}\""; execute_command($command); } |
Author: | TinyWebGallery [ 28. Oct 2014, 15:17 ] |
Post subject: | Re: save pdf file but doesn't show |
Why is [0] there.? |
Author: | pumin [ 28. Oct 2014, 17:14 ] |
Post subject: | Re: save pdf file but doesn't show |
[0] will generate only first page of pdf file. |
Author: | TinyWebGallery [ 28. Oct 2014, 17:28 ] |
Post subject: | Re: save pdf file but doesn't show |
o.k. i will make the 120 dynamic and add this to the next build... |
Author: | pumin [ 2. Nov 2014, 21:55 ] |
Post subject: | Re: save pdf file but doesn't show |
Thank you Mike. Also I have another mod to have TWG read keywords from PDF and it works ok so far. In case it may be useful, please feel free to modify the code. readxml.inc.php Code: function get_iptc_data($twg_album, $image, $iptc_array, $stOnly = false)
//mod by Pumin { global $basedir, $use_iptc_tags, $charset, $iptc_encoding, $iptc_fields_for_imagetags; $keywords = null; if ($use_iptc_tags) { $remote_image = twg_checkurl($basedir . "/" . $twg_album); if ($remote_image) { $filename = getRemoteImagePath($remote_image, $image); } else { $filename = $basedir . "/" . $twg_album . "/" . $image; } $offp = getExtension($image); if ($offp != 'pdf' ) { set_error_handler("on_error_no_output"); // images with errors are ignored $oldsize = @getimagesize($filename, $info); set_error_handler("on_error"); if (isset($info["APP13"])) { $iptc = iptcparse($info["APP13"]); if (is_array($iptc)) { foreach ($iptc_array as $key) { if (isset($iptc[$key])) { $keywordcount = count($iptc[$key]); for ($i = 0; $i < $keywordcount; $i++) $keywords .= $iptc[$key][$i] . ","; if ($stOnly) { break; } } } } } if (isset($keywords)) { $keywords = substr($keywords, 0, -1); } } elseif ($offp == 'pdf' && !$remote_image && $iptc_array == $iptc_fields_for_imagetags) { $content = getXmpData($filename); $xmp_data_start = strpos($content, '<dc:subject'); $xmp_data_end = strpos($content, '</dc:subject>'); $xmp_length = $xmp_data_end - $xmp_data_start; if ($xmp_length > 0) { $keywords = substr($content, $xmp_data_start, $xmp_length + 13); $keywords = preg_replace("/<\/rdf:li>\s\s+<rdf:li>/", ",", $keywords); $keywords = preg_replace("/>\s\s+</", "><", $keywords); $keywords = strip_tags($keywords); } } } if (isset($charset) && strtolower($charset) == "utf-8" && $iptc_encoding != 'utf-8') { $keywords = utf8_encode($keywords); } return $keywords; } function getXmpData($filename, $chunk_size = 50000){ //credit to Bryan Geraghty, Sebastien B. & Lukáš Řádek @stackoverflow.com $buffer = NULL; if (($file_pointer = fopen($filename, 'r')) === FALSE) { throw new RuntimeException('Could not open file for reading'); } $chunk = fread($file_pointer, $chunk_size); if (($posStart = strpos($chunk, '<x:xmpmeta')) !== FALSE) { $buffer = substr($chunk, $posStart); $posEnd = strpos($buffer, '</x:xmpmeta>'); $buffer = substr($buffer, 0, $posEnd + 12); } fclose($file_pointer); // recursion here if(!strpos($buffer, '</x:xmpmeta>')){ $buffer = getXmpData($filename, $chunk_size*2); } return $buffer; } |
Page 1 of 1 | All times are UTC + 1 hour [ DST ] |
Powered by phpBB® Forum Software © phpBB Group http://www.phpbb.com/ |