Php photo gallery TWG | JFUploader | TWG Flash upload | WFU | Forum

Get help for TinyWebGallery, the best image gallery. The forum is also home for the Joomla JFUploader, TWG Flash Uploader and the Wordpress flash uploader.
It is currently 22. Nov 2024, 02:51

This forum is readonly now. Please use the new forum if you don't find the answer to your question here. The new forum is at https://www.tinywebgallery.com/blog/forum/


All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: 17. Oct 2014, 19:09 
Offline
User avatar

Joined: 17. Oct 2014, 18:58
Posts: 7
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


Top
 Profile  
 
PostPosted: 20. Oct 2014, 09:54 
Offline
Site Admin
User avatar

Joined: 1. Aug 2005, 12:53
Posts: 11232
Why should pdf show? You always need a preview image.
Please check the howto for support of other file types.

Best,
Michael


Top
 Profile  
 
PostPosted: 23. Oct 2014, 04:01 
Offline
User avatar

Joined: 17. Oct 2014, 18:58
Posts: 7
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!


Top
 Profile  
 
PostPosted: 23. Oct 2014, 09:22 
Offline
Site Admin
User avatar

Joined: 1. Aug 2005, 12:53
Posts: 11232
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


Top
 Profile  
 
PostPosted: 28. Oct 2014, 15:08 
Offline
User avatar

Joined: 17. Oct 2014, 18:58
Posts: 7
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);
        }


Top
 Profile  
 
PostPosted: 28. Oct 2014, 15:17 
Offline
Site Admin
User avatar

Joined: 1. Aug 2005, 12:53
Posts: 11232
Why is [0] there.?


Top
 Profile  
 
PostPosted: 28. Oct 2014, 17:14 
Offline
User avatar

Joined: 17. Oct 2014, 18:58
Posts: 7
[0] will generate only first page of pdf file.


Top
 Profile  
 
PostPosted: 28. Oct 2014, 17:28 
Offline
Site Admin
User avatar

Joined: 1. Aug 2005, 12:53
Posts: 11232
o.k. i will make the 120 dynamic and add this to the next build...


Top
 Profile  
 
PostPosted: 2. Nov 2014, 21:55 
Offline
User avatar

Joined: 17. Oct 2014, 18:58
Posts: 7
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. :D

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;
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 18 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
cron
powered by phpbb | Datenschutz/ Privacy policy