• Resolved podi

    (@podi)


    hi,
    can you tell me how add emagick blur filter
    and use the thumbnail as featured please?
    ive try to add code in your PdfThumbnailsPlugin.php but server return error:
    (work after refresh media page but with black borders…)
    code:

    private function getThumbnailBlob($filename)
    {
    $blob = apply_filters(‘pdf_thumbnails_generate_image_blob’, null, $filename);
    if ($blob) {
    return $blob;
    }
    $imagick = new Imagick($filename);
    $imagick->blurImage(5,3);
    $imagick->setIteratorIndex(0);
    $imagick->setImageFormat(‘jpg’);
    return $imagick->getImageBlob();
    }

    thanks in advance for reply

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author stianlik

    (@stianlik)

    I haven’t tested this, but I think you have to rearrange the code so that $imagic->blurImage is placed after $imagic->setImageFormat. I don’t think you can blur the image before we have selected an image to work with.

    $imagick = new Imagick($filename);
    $imagick->setIteratorIndex(0);
    $imagick->setImageFormat('jpg');
    $imagick->blurImage(5,3);
    return $imagick->getImageBlob();
    
    • This reply was modified 4 years, 5 months ago by stianlik.
    • This reply was modified 4 years, 5 months ago by stianlik.
    Thread Starter podi

    (@podi)

    result:
    result

    same…
    so,
    1.how have image without black borders?
    2.how reduce thumbnail size?
    thanks

    Thread Starter podi

    (@podi)

    Plugin Author stianlik

    (@stianlik)

    You can adjust thumbnail sizes as described in Post Thumbnails and you may be able to trim the black border using trimImage.

    In any case, you may want to look at another plugin or try to use the built-in PDF thumbnail feature from WordPress. PDF Thumbnails is not maintained and was last updated 4 years ago.

    Thread Starter podi

    (@podi)

    ok stianlik
    thanks for reply
    i think i ve solve the problem
    and i realy want to use your plugin.

    now, can i ask you another think?
    i’m not a coder
    but you understand code

    link

    here is a link for add description and atribute to image,
    i think you can tell me what i need to change in your file for make same ?

    if you dont want take any time for me, no problem…
    thanks in advance

    Plugin Author stianlik

    (@stianlik)

    I’m glad you were able to solve the problem.

    If you’d like to set the alt attribute of the thumbnail to the same as the post title for your attachment (PDF), you should be able to do it with something like the following code sample.

    The trick is to use get_post_thumbnail_id($attachmentId) to get the ID for the generated thumbnail. It is also important that you include the number 11 as shown at the bottom, this is the priority of your filter, we use 11 to make sure that it is executed after the the thumbnails are generated.

    add_filter('wp_generate_attachment_metadata', function ($metadata, $attachmentId) {
        if (get_post_mime_type($attachmentId) === 'application/pdf') {
            $thumbnailId = get_post_thumbnail_id($attachmentId);
            if ($thumbnailId) {
                $pdfAttachment = get_post($attachmentId);
                if ($pdfAttachment) {
                    update_post_meta($thumbnailId, '_wp_attachment_image_alt', $pdfAttachment->post_title);
                }
            }
        }
        return $metadata;
    }, 11, 2);

    Note that this code is not tested, you may need to tweak it a bit to make it work.

    • This reply was modified 4 years, 5 months ago by stianlik.
    • This reply was modified 4 years, 5 months ago by stianlik.
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘blur and featured’ is closed to new replies.