• Hi, I’ve started using Cloudinary plugin and it works quite well. But among all my media files there are some GIFs (~100 files) I would like to display as MP4 but they are obviously considered as image by default so they inherit from transformations for image.
    Is it possible to specify custom transformations for GIF files in an other way than specifiying transformations on taxonomy or file directly?

    I guess it would be possible to do something with filters but there are so many and there is no examples so I feel a bit loss.

    • This topic was modified 1 year, 5 months ago by Luc Poupard. Reason: Comment about filters
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support loic @ cloudinary

    (@loiccloudinary)

    Hi @kloh,

    As documented here, it is a matter of switching the extension.
    Let me work on a custom filter so you can use it on your side. In the meantime, could you let me know how big your GIFs are?
    Thanks in advance.

    Best,

    Loic

    Plugin Support loic @ cloudinary

    (@loiccloudinary)

    Hi @kloh,

    Thanks for your patience.

    Here are the steps to do this:

    You will need to first add the f_mp4 individual transformation to the asset as documented here. Then you will need to add the following code in your functions.php

    add_filter(
    'cloudinary_pre_image_tag',
    static function ( $tag ) {
    // take the image element and switch it to a video tag 
    if ($tag['id'] == '93576'){
    $tag['tag'] = "video";
    $tag['type'] = "video";
    $tag['format'] = "mp4";
    unset($tag['atts']['height']);
    unset($tag['atts']['width']);
    unset($tag['atts']['decoding']);
    unset($tag['atts']['loading']);
    unset($tag['atts']['alt']);
    unset($tag['atts']['data-responsive']);
    unset($tag['atts']['srcset']);
    unset($tag['atts']['sizes']);
    $tag['atts']['0'] = "controls";
    unset($tag['loading']);
    }
    return $tag;
    }
    );

    Hope that helps.

    Best,

    Loic

    Thread Starter Luc Poupard

    (@kloh)

    Thank your for your feedback!

    So to be clear I still need to add f_mp4 transformation on the file directly. Not that ideal but I keep it as an option and give it a try. ??

    Plugin Support loic @ cloudinary

    (@loiccloudinary)

    That’s right @kloh.

    Feel free to reach out if you need anything.

    Best,

    Loic

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Specific transformation for GIF’ is closed to new replies.