• Mario

    (@ejamo)


    Hi, I have a problem with the plugin, it renames the file correctly but does not perform the replace within the posts.

    I think the problem is because I use a custom thumbnail format like this:

    • picture-hd.jpg (original file)
    • picture.jpg (large)
    • picture-medium.jpg (medium)
    • picture-thumbnail.jpg (thumbnail)

    This change to the filenames is made by a function that filters ‘image_make_intermediate_size’:
    add_filter( ‘image_make_intermediate_size’, ‘custom_images_filename’ );

    Your plugin was working correctly until some past version, then I don’t know from which version onwards it stopped working.
    How can I pass the custom file format information to the plugin?
    Thank you very much

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter Mario

    (@ejamo)

    no idea?

    Plugin Author crossi72

    (@crossi72)

    Hi @ejamo,
    I’m sorry for my late reply, I’ll check immediately this issue and let you know if I can release a fix.

    Thank you for reporting.
    C.

    Plugin Author crossi72

    (@crossi72)

    Hi @ejamo,
    I’m finally back in the office, can you tell me which code are you using in the custom_images_filename method, so that I can replicate your issue?

    Thank you
    C.

    Thread Starter Mario

    (@ejamo)

    Hi, don’t worry for delay.
    The following code create these thumbnails when we load a picture with “-hd” prefix, i.e. colosseum-hd.jpg

    • colosseum-hd.jpg (original file)
    • colosseum.jpg (large)
    • colosseum-medium.jpg (medium)
    • colosseum-thumbnail.jpg (thumbnail)
    add_filter( 'image_make_intermediate_size', 'custom_images_filename' );
    function custom_images_filename( $image ) {

    ? ? // Info file

    ? ? $info = pathinfo($image);
    ? ? $dir = $info['dirname'] . '/';
    ? ? $ext = '.' . $info['extension'];
    ? ? $name = wp_basename( $image, "$ext" );
    ? ? $hd= '-hd';

    ? ? // If image is High Definition remove prefix
    ? ? if(strpos($name,$hd) !== false) {
    ? ? ? ? $name = str_replace($hd,'',$name);

    ? ? // If image is Low Definition don't change filename but add '-hd' to "large" dimension
    ? ? } else {
    ? ? ? ? $force_prefix = 'yes';

    ? ? }

    ? ? // Get image information
    ? ? $img = wp_get_image_editor( $image );
    ? ? $img_size = $img->get_size();

    ? ? // Image prefix for builtin sizes
    ? ? $widths = [];
    ? ? $size_based_img_name_prefix = '';

    ? ? foreach ( get_intermediate_image_sizes() as $_size ) {

    ? ? ? ? $width = get_option( "{$_size}_size_w" );

    ? ? ? ? if ( ! isset( $widths[ $width ] ) ) {
    ? ? ? ? ? ? $widths[ $width ] ?= $_size;
    ? ? ? ? }

    ? ? }

    ? ? if ( array_key_exists( $img_size[ 'width' ], $widths ) ) {
    ? ? ? ? if($widths[ $img_size['width'] ]!='large' || $force_prefix=='yes') $size_based_img_name_prefix = '-'.$widths[ $img_size['width'] ];

    ? ? ? ? $name_prefix = substr( $name, 0, strrpos( $name, '-' ) );

    ? ? } else {
    ? ? ? ? $name_prefix = $name;

    ? ? }

    ? ? // Build our new image name
    ? ? $new_name = $dir . $name_prefix .$size_based_img_name_prefix . $ext;

    ? ? // Rename the intermediate size
    ? ? $did_it = rename( $image, $new_name );

    ? ? // Renaming successful, return new name
    ? ? if( $did_it ) {
    ? ? ? return $new_name;

    ? ? } else {
    ? ? ? return $image;

    ? ? }

    }

    The plugin works fine with filenames without “-hd” (both in renaming them and in performing the replace within the content of posts) while with files containing “-hd” it only renames them but does not perform the replace within posts.

    Thank you

    Plugin Author crossi72

    (@crossi72)

    Hi @ejamo,
    everything worked in my tests, maybe the image resolution is involved, can you send me at support@eurosoftlab.com a test image that causes the issue on your server?

    Thank you
    C.

    Thread Starter Mario

    (@ejamo)

    Hi, thank you for the tests you have done.

    I don’t think it depends on the single photo, because we have tried dozens of them and unfortunately the problem is always the same.

    I have to say that until a few versions ago everything was working correctly, so I don’t know what might have changed or if a conflict with other plugins might have occurred (although to be honest we use very few of them).

    Could it be a problem related to the priority with which operations are executed? Any other ideas on what to investigate?

    Thank you again

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.