Support » Plugin: PDF Thumbnails » how to set size of thumbnail image

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

    (@stianlik)

    Images are generated using the built-in WordPress thumbnail features so that you can manage the sizes as described in the codex.

    mdubey

    (@mdubey)

    no actually , i want some thing like this in order to set generated image size for my all pdf

    add_action(‘pdf_thumbnails_generate_image_blob’, function ($blob, $filename) {
    $imagick = new Imagick();
    $imagick->setResolution(200,200);
    $imagick->readImage($filename);
    $imagick->setIteratorIndex(0);
    $imagick->setImageFormat(‘jpg’);
    return $imagick->getImageBlob();
    }, 10, 2);

    because i have to upload many pdf images with same size about 770*450

    mdubey

    (@mdubey)

    and this is the page where i have to use this generated image

    TESTIMONIANZE DEI PARROCI

    so here i needed all images should be same size about 770*450

    please help me asap

    mdubey

    (@mdubey)

    please tell me sir , is there any way to restrict the size of generated image to about 770*450

    i searched the web there are many method of imagic which can do that but i don’t know how to use it so please tell me about the code so that i can fix my problem

    i only want to set generated pdf image size to 770*450

    thank you

    Plugin Author stianlik

    (@stianlik)

    I recommend that you use the thumbnail built into WordPress to define image sizes, but it is also possible to do it manually using scaleImage. The following should limit your image width to 770px:

    add_action('pdf_thumbnails_generate_image_blob', function ($blob, $filename) {
        $imagick = new Imagick($filename);
        $imagick->setIteratorIndex(0);
        $imagick->setImageFormat('jpg');
        $imagick->scaleImage(770, null, true);
        return $imagick->getImageBlob();
    }, 10, 2

    The preceding code has not been tested, but it should give you an idea of how to achieve your goal.

    There are many possibilities in Imagick, you could also crop the image.

    mdubey

    (@mdubey)

    sir i apply this code it generate error …. server not found error

    please try to give me tested code so that i can fix my code

    i am very needful

    mdubey

    (@mdubey)

    i try other possibility of code but it generate http error

    my code was

    add_action(‘pdf_thumbnails_generate_image_blob’, function ($blob, $filename) {
    $imagick = new Imagick();

    $imagick->readImage($filename);
    $imagick->setIteratorIndex(0);
    $imagick->setImageFormat(‘jpg’);
    $imagick->scaleImage(0, 450, true);
    return $imagick->getImageBlob();
    }, 10, 2);

    mdubey

    (@mdubey)

    please sir help me to resolve this issue , i want the code by which i can fix width and height

    Thank you sir

    Plugin Author stianlik

    (@stianlik)

    Seems like scaleImage does not support auto-calculating height values with $bestfit defined. You can use the following sample to size your image exactly 770x450.

    add_action('pdf_thumbnails_generate_image_blob', function ($blob, $filename) {
        $imagick = new Imagick($filename);
        $imagick->setIteratorIndex(0);
        $imagick->setImageFormat('jpg');
        $imagick->thumbnailImage(770, 450, true, true);
        return $imagick->getImageBlob();
    }, 10, 2);

    If you only want to limit the width to 770, you can use the following sample:

    add_action('pdf_thumbnails_generate_image_blob', function ($blob, $filename) {
        $imagick = new Imagick($filename);
        $imagick->setIteratorIndex(0);
        $imagick->setImageAlphaChannel(Imagick::ALPHACHANNEL_OPAQUE);
        $imagick->setImageFormat('jpg');
        $imagick->resizeImage(770, 0, Imagick::FILTER_POINT, 1);
        return $imagick->getImageBlob();
    }, 10, 2);

    If you would like to learn more about Imagick, there is a tutorial on SitePoint.

    mdubey

    (@mdubey)

    Thank you sir ,

    its really very helpful for me and now i am very happy to fix my problem

    you are great person

    thank you sir

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘how to set size of thumbnail image’ is closed to new replies.