mla_galery thumbnails are too small.
-
Hi David, hope you’re doing well.
All of a sudden my [mla_galery] thumbnails started displaying at max 64×64 pixels as can be seen in this image. I remembered I recently updated to 2.01 (from 1.95 I think)
I went in the support forum and found this thread, where I noticed the new version substitutes mla_viewer=true for size=icon, overriding any other size= specified, apparently!
I know the change was intended as a fix for Google dropping support for generating doc thumbs. The problem is this is applied to all image elements and not only documents.
For now I can either stick to an older version and/or remove the mla_viewer=true option, however I thought I’d ask you about it in case there’s another way thisit with the latest version.
Cheers.
-
Thanks for bringing this to my attention. As you observed, the size=icon substitution was an emergency fix, and I hadn’t considered a mix of images and PDF documents in the same gallery.
I will try to improve things as quickly as I can. If you return to an older version you will get a “broken image” icon for your PDFs but the images will display. If you remove the
mla_viewer
parameter I believe you will get the document title in place of the image/icon for PDFs. What would you like to see (other than Google reversing its decision)? Do you want a big, fuzzy icon or a small, crisp icon, or the document title, or?? There’s no obvious choice…Yes, when downgrading the broken images will be displayed. I kept the newer version and removed the mla_viewer param, and indeed I get the document titles instead which is a more graceful degradation.
Could the icon size only apply to documents so that we get the PDF logo, for example, but just for PDFs?
Ideally a live thumb of the doc would be great. I will look around to see if I find anything useful we can incorporate here.
Q. For the longer-term, do you think we should worry about Google further changing or discontinuing their doc viewer?
Thanks
Thanks for your update and for your comments on the limited alternatives for a more graceful short-term solution to the
mla_viewer
problem. I will look at an interim fix that returns icons for non-image items whenmla_viewer
is present, and perhaps adjusting the size of the icon in some optional way.In the longer term I have two ideas: 1) find some kind of “live thumbnail” support, and 2) provide for “cover art” along the lines that BuddyPress uses or video and audio files. Cover art would let you name something like a “Featured Image” for items, which would be used for a thumbnail display.
As far as I can tell, the Google Doc Viewer is being “improved” for use with Google Drive and Google Doc services. There is some capability for using it with documents not hosted by Google, but the new APIs are complex and I have not investigated them in any detail. The thumbnail feature is still used within Google Drive but no longer exposed for remote use.
Here is the response from another popular WordPress plugin:
Google Doc Embedder (see the NOTE: on the Description tab).
PDF Embedder for WordPress (a new replacement for Google Doc Embedder)
I have corresponded with the authors of those plugins to see if there’s some potential for cooperation.
Sounds great. Thanks for going out of your way in mentioning these very interesting alternatives or additions. PDF Embedder sounds ideal, I signed up for their newsletter.
For now we will have to live with the lack of doc thumbnails in mla_gallery . The rest of the plugin is still very much a uniquely useful tool.
Thanks
I have just uploaded a new Development Version that improves the handling of
mla_viewer
simulation.If you code
mla_viewer=true
icons will replace the thumbnail images only for those items that do not generate a thumbnail of their own. So, for example, galleries with a mix of images and PDF documents will look more reasonable. You can adjust the size of the icons with themla_viewer_width
parameter; the default is 150×150 pixels.Step by step instructions for installing the Development Version can be found in this earlier topic:
Please let me know if you give this a try and/or if you have any additional suggestions regarding the interim fix. Thanks!
OK. I installed dev version 2.01 20150206.
With mla_viewer=true on, PDF icons display only for PDFs, which is nicer than before so thanks.
Let’s see what happens with https://pdf-embedder.instapage.com/
also, this article mentions ImageMagik https://stackoverflow.com/questions/467793/how-do-i-convert-a-pdf-document-to-a-preview-image-in-php have you considered that? I didn’t look too deeply into it.Oh one more Q. Is there a way to include a caption only for the PDF icons? It seems mla_caption will apply to everything. Thanks!
Thank you for your update with the good news regarding the 20150206 MLA Development Version.
Regarding “this article mentions ImageMagik“, I have looked at that in the past but it requires both ImageMagik and GhostScript to be installed on the server, and I don’t know how universal that configuration is. If you are interested in a solution along those lines I can work with you to try it out. It would be a useful extension to my “custom plugin” answer to your next question.
Regarding “Is there a way to include a caption only for the PDF icons?“, I have developed a small custom plugin that provides this feature. The complete example plugin has been uploaded to the MLA Development Version (20150210). You can find it in the
/examples/mla-viewer-replacement-example.php.txt
file. Here are the essential elements.The
initialize
function hooks three of the provided filters when called from the “front end” site:public static function initialize() { /* * The filters are only useful for front-end posts/pages; exit if in the admin section */ if ( is_admin() ) return; /* * add_filter parameters: */ add_filter( 'mla_gallery_raw_attributes', 'MLAViewerReplacement::mla_gallery_raw_attributes', 10, 1 ); add_filter( 'mla_gallery_arguments', 'MLAViewerReplacement::mla_gallery_arguments_filter', 10, 1 ); add_filter( 'mla_gallery_item_values', 'MLAViewerReplacement::mla_gallery_item_values_filter', 10, 1 ); }
The raw attributes filter captures the shortcode parameters and saves them for use in the items filter. The gallery arguments filter captures all of the possible parameters, including default values for the list of file extensions used by the “viewer” logic.
The interesting code is in the item values filter. This filter is called once for each item in the gallery, and is supplied with all of the substitution parameter values (
$item_values
) for the item, e.g., the file name for the item.public static function mla_gallery_item_values_filter( $item_values ) { /* * We use a shortcode parameter of our own to apply our filters on a * gallery-by-gallery basis, leaving other [mla_gallery] instances untouched. * If "mla_viewer_caption" is not present, we have nothing to do. Here is * an example of how the custom parameter can be used: * * [mla_gallery ids="2621,2622,2623" mla_viewer=true mla_viewer_caption="{+title+}"] */ if ( ! isset( self::$shortcode_attributes['mla_viewer_caption'] ) ) { return $item_values; } $extension = pathinfo( $item_values['file'], PATHINFO_EXTENSION ); if ( false === strpos( self::$all_display_parameters['mla_viewer_extensions'], $extension ) ) { return $item_values; } // You can use MLAOptions::mla_get_data_source() to get anything available. $mla_viewer_caption = str_replace( '{+', '[+', str_replace( '+}', '+]', self::$shortcode_attributes['mla_viewer_caption'] ) ); $data_source = array( 'data_source' => 'template', 'meta_name' => $mla_viewer_caption, 'option' => 'text' ); $mla_viewer_caption = MLAOptions::mla_get_data_source( $item_values['attachment_ID'], 'single_attachment_mapping', $data_source, NULL ); $item_values['caption'] = $mla_viewer_caption; return $item_values; } // mla_gallery_item_values_filter
As you can see, this function looks for a
mla_viewer_caption
parameter. If the parameter is present and, if the item has a file extension that matches an entry in themla_viewer_extensions
list, a new caption is composed for the item. The parameter value is a Content Template, so you can compose a new caption from multiple sources. For example, if you code:[mla_gallery ids="2621" mla_viewer=true mla_viewer_caption="({+post_excerpt+}|{+post_title+}"]
The caption for “viewer” items such as PDF documents will be the
post_excerpt
(the default caption) if the item has one or thepost_title
(the item’s Title) if thepost_excerpt
is empty.You can combine this custom parameter with the existing
mla_caption
parameter for other gallery items like images. Each file type will get the appropriate value.I encourage you to download the latest version and let me know how it works for you. Thanks for continuing an interesting topic.
Hi David, sorry for the delay.
I implemented the example plugin code in my theme functions.php (with slight modifications) and it works as expected. (I included your copyright/license comment.)
I feel like the mla_viewer_caption param could be native in the shortcode but up to you.
Thanks again!
Thanks for the update. I am happy to hear the code is working for you.
I will think about including this feature in a future MLA version, as part of a more useful “viewer” feature that restores an ability to show thumbnails for non-image items like PDF documents.
Thank you for working with me on this issue.
Hey David quick Q. Any thought on how to truncate the value of a substitution parameter? Something like make
mla_viewer_caption=[+post_excerpt,truncate(30)+]
or something like that?
Or, perhaps a filter such as mla_gallery_item_values could also be used? I looked around in the plugin documentation but it’s a bit extensive, wasn’t sure how to look for this info without reading the whole thing.
Thanks in advance.
Thanks for an interesting idea. Since the
mla_viewer_caption
is already handled by a small custom plugin I can do something there without too much trouble. Give me a day or two come up with something.I have just uploaded a new Development Version with a field-level format option that will accomplish your goal. This turned out to be easier than modifying the custom plugin.
With the new version you can limit the size of a value by coding something like:
mla_viewer_caption=[+post_excerpt,substr(0,30)+]
As you can see, the new “substr” format option will accept start and length arguments and return the corresponding portion of the value. This option uses the PHP
substr()
function, which is more flexible than a hard-coded “truncate” option.The new format option can be used anywhere a field-level substitution value occurs; it is not limited to the
mla_viwer_caption
custom parameter.If you have a chance to try the Development Version let me know of you have any problems or further questions regarding the new option. Thanks for inspiring this MLA enhancement.
I have run some experiments with an
mla_viewer
replacement that uses Imagemagick and Ghostscript to produce PDF thumbnails on the local server. It works, but performance is uneven. Small PDF documents are processed in a few seconds, but larger documents are impractical (as they were with the earlier Google implementation). One of my test documents is 32MB and requires 107 seconds (1.78 minutes) to process. It appears that the entire document is generated even though the thumbnail comes from page 1.If you want to play with this experimental version, let me know. I will work on a version that generates the thumbnails ahead of time and supports some sort of “cover art” feature along the lines BuddyPress uses for audio and video files.
I have an improved experimental version of the “Google File Viewer replacement” feature:
- The “Imagemagick thumbnail” implementation is faster and more reliable.
- You can now assign a “Featured Image” to any Media Library item, such as a PDF document. If you do, the image is used a thumbnail for the item instead of generating an “Imagemagick thumbnail” on the fly.
I am still working on some other aspects of this project:
- Detect missing Ghostscript support without crashing the server.
- Use Imagemagick to generate an PDF single-page image manually, saving it as a Media Library item that can become the “Featured Image” of the document without on-the-fly delays.
- Add some hooks to give more control over the various options.
The new “mla_viewer” feature has several parameters:
mla_viewer
– set this to “true” to activate the viewer.mla_viewer_extensions
– set this totxt
to prevent PDF processing when Ghostscript is not installed but Imagick is installed.mla_viewer_limit
– set this to a value in MB to limit PDF processing to files smaller than the parameter value.mla_viewer_width
– set this to a positive value to limit the width of the generated thumbnails.mla_viewer_height
– set this to a positive value to limit the height of the generated thumbnails.mla_viewer_page
– set this to 2 or higher to select that document page as the thumbnail. Default is the first/only document page.mla_viewer_resolution
– set this something higher than the default (72) to increase the quality of the thumbnail image; try 200 or 300.mla_viewer_type
– set this to “image/png” to return thumbnails in that format; default is “image/jpeg”.
If you set neither
mla_viewer_width
normla_viewer_height
, the default process will return thumbnails with a width of 150px and a proportional height. If you set both, the image will be exactly the height and width you set, which may distort some images.If you set
mla_viewer_resolution
to a high value the images will look great but take longer to process.If you set
mla_viewer_type
to “image/png” the background will be transparent and image generation may be slightly faster. The default jpeg images will have a white background.
- The topic ‘mla_galery thumbnails are too small.’ is closed to new replies.