Apache server and GhostScript and use dg in loop.php
-
I see that Imagick is configured, but I’m having a hard time configuring GhostScript for Apache php (OSX Mavericks). Do you know of any step by step for this process? I’ve compiled and installed GhostScript, but my server cannot see it.
I also wish to use dg in loop.php, much like post thumbnails. How is this accomplished?
-
Hi beneficialmedia,
I’ve actually never tested Document Gallery on an OSX system, but I can’t think of any reason it would not work. From the sounds of it, the plugin isn’t automatically detecting the location of Ghostscript. To fix that, all you should need to do is go to the Document Gallery settings page and at the very bottom is a field where you can enter the absolute path to the Ghostscript executable and fill that value in.
In terms of calling DG in other locations, you can use
do_shortcode()to get a Document Gallery anywhere within the code.-Dan
PS: If you’ve found this plugin useful, please take a moment to rate it. Thanks! π
Thanks, Dan!
The absolute path did the trick.
However, when I use in loop.php:
<div class="inheritssomeclass"> <?php echo do_shortcode('[dg fancy=true]'); // We display pdf and word thumbnails ?> </div>…it returns something like 600 thumbnails in the loop. How do I reference this short code like a post thumbnail? So that it only returns the search results I want?
//Dylan
beneficialmedia,
You’re saying that you want to get the thumbnail for an individual post ID? The shortcode will unfortunately not be a good option for that.
What you could do is directly access the method doing that generation,
DG_Thumber::getThumbnail(), which can be seen here.The method returns a URL pointing to the thumbnail for whichever attachment ID it is given, or a default icon if no thumbnail can be generated.
-Dan
I understand the concept, but I don’t have any experience directly accessing methods. Would you please provide more details of how to do this?
What exactly is it that you are trying to do? If I’m understanding correctly, you’re working in the PHP code itself. Are you developing a plugin?
-Dan
PS: If you’ve found this plugin useful, please take a moment to rate it. Thanks! π
I’m developing a custom theme. For this case, I’m editing loop.php to support the search everything plugin along with the Media Library Assistant plugin to return a list of tagged pdf and word docs from the media library. My goal is to adapt your plugin to return a thumbnail of the search results in the loop.
//Dylan
Gotcha.
Well, in order to directly call the method, as long as Document Gallery is enabled, you should just be able to put
DG_Thumber::getThumbnail()where you want to have the path to the thumbnail returned to.getThumbnail()takes the attachment ID as an argument. If you’re in the loop at the loop is referencing attachments (rather than posts/pages), then this should be all you need. If you have any non-attachments in the loop, you may want to check whether each item is an attachment before calling the method.Note that this is not documented functionality and could potentially change in future versions. There are no plans for this to happen, but you should always check new DG versions on a test server before putting it on your production server.
-Dan
PS: If you’ve found this plugin useful, please take a moment to rate it. Thanks! π
I’ve almost got it. How do I ensure it returns the fancy thumber path and not the default if I’m using this as an img src path?
Here’s my block:
<!-- attachment thumbnail --> <?php if (wp_get_attachment_url($attachment_id) != null) : // Check if doc gallery thumbnail exists ?> <a href="<?php the_permalink(); ?>" class="inheritssomeclass" style="position: absolute; top: 0; left: 0; width: 88px; height: 114px; background: #CCCCCC; border: 1px solid #000000; text-decoration: none; overflow: hidden;"> <img src="<?php echo DG_Thumber::getThumbnail(); // We display pdf and word thumbnails ?>" style="width: 100%; height: auto;"/> </a> <?php endif; ?> <!-- /attachment thumbnail -->So I figured out that I need to do something like DG_Thumber::getThumbnail(3205, 1);
the number 3025 is the attachment id. What variable returns this number? I may figure it out soon, but if you know that would be cool too.
This is very close…
<!-- attachment thumbnail --> <?php if (wp_get_attachment_url($attachment_id) != null) : // Check if doc gallery thumbnail exists ?> <a href="<?php the_permalink(); ?>" class="inheritssomeclass" style="position: absolute; top: 0; left: 0; width: 88px; height: 114px; background: #CCCCCC; border: 1px solid #000000; text-decoration: none; overflow: hidden;"> <img src="<?php echo DG_Thumber::getThumbnail(get_the_ID()); // We display pdf and word thumbnails ?>" style="width: 100%; height: auto;"/> </a> <?php endif; ?> <!-- /attachment thumbnail -->get_the_id() returns the attachment id. However, I noticed that many of the pdf’s only show the default thumbnail. Is there a special setting in a pdf that works with Imagick/GhostScript?
beneficialmedia,
Here is what I would do, based on what you’ve started with:
<!-- attachment thumbnail --> <?php if ($post->post_type === 'attachment') : <a href="<?php the_permalink(); ?>" class="inheritssomeclass" style="position: absolute; top: 0; left: 0; width: 88px; height: 114px; background: #CCCCCC; border: 1px solid #000000; text-decoration: none; overflow: hidden;"> <img src="<?php echo DG_Thumber::getThumbnail(get_the_ID()); // We display pdf and word thumbnails ?>" style="width: 100%; height: auto;"/> </a> <?php endif; ?> <!-- /attachment thumbnail -->I’m using get_the_ID to find the current ID and I replaced you method for detecting whether you have an attachment with a more straightforward look at the current $post object.
Let me know how that works for your needs.
-Dan
PS: If you’ve found this plugin useful, please take a moment to rate it. Thanks! π
The layout works perfectly! I’m very happy with that, now onto a new issue. It seems that document gallery times out before it generates all the thumbs. I changed the timeouts from 30 secs and 60 secs to 3600 secs. This kinda worked… The plugin generated many more thumbnails than before, but still there are many that didn’t generate. I guess my question is, how do I generate all the thumbnails? I’d like to hack a solution, then undo the hack for all the one-off PDFs in the future, allowing your plugin to do its job. The PDFs all have read and write permissions and all seem to be capable. Would the pdf file sizes make a difference? Some are 5-7 megs. Maybe the PDFs need to be exported with some setting to allow the generation of these pngs?
beneficialmedia,
For your first question, you can actually just remove the logic to time out generation. Should be a block inside an that checks the value you’ve been tweaking.
For the second half of your question, it’s hard to say. There are a lot of different kinds of PDFs. You could pull out the command I’m passing to the command line and test any specific PDFs you’re having issues with, but beyond that I can’t be of much help.
-Dan
The topic ‘Apache server and GhostScript and use dg in loop.php’ is closed to new replies.