aelvan / Imager-Craft

This plugin has been DEPRECATED. Check out Imager X instead.
MIT License
342 stars 69 forks source link

temporary image / pre transform and double hash #274

Closed MrGlasspoole closed 5 years ago

MrGlasspoole commented 5 years ago

I did read the "9 tips" article and do the pre transform (4. Reduce the size of the source image).

The thing is that the files get a double hash what makes really long filenames. the-name-of-my-image_d5836807d7416256748889b4cab36b2f_0d86a0a781f23c89d6213036f06875c2.jpg

Is there a way to prevent that?

aelvan commented 5 years ago

Well, not sure if it's worth it, but you could override the filenamePattern config setting in your second transform, to generate a shorter filename, using the original file's basename and a hash of the full name of the first transform. Something like filenamePattern: originalFileName ~ '_{fullname|hash}.{extension}' (you can also replace |hash with |shorthash, but beware that file name collisions may occur). From the top of my head I don't remember exactly how you'd get that file name (withour the extension), but check the AssetModel docs.

MrGlasspoole commented 5 years ago

Thanks that works. Only thing i also did is trimming the extension.

{% set image = row.textImage.one() %}
{% set fileName = image.filename|trim('.' ~ image.extension, 'right') %}

{% set transformedImages = craft.imager.transformImage(tempImage, imageSizes,
    {
        format: imageType,
        allowUpscale: false,
        resizeFilter: 'lanczos',
        effects: { unsharpMask: [0, 0.55, 0.55, 0.008] },
        interlace: false,
        convertToRGB: true,
        filenamePattern: fileName ~ '_{fullname|hash}.{extension}'
    }
) %}