• Resolved jashaw

    (@jashaw)


    When I try to compress some of my images I get the above mentioned error. I have verified that the file does exist.
    I get the same issue with all relevant plugins deactivated. The only idea I have is that this plugin has incorrect filename data on these files somewhere in the wordpress db. I do use a plugin the renames files to a web friendly format. It is feasible that these 2 plugins do not play nicely together and the damage would be in the db not just from having the plugin activated.

    Thoughts?

    https://www.ads-software.com/plugins/tiny-compress-images/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter jashaw

    (@jashaw)

    So the issue here is with the rename plugin I mentioned.

    Plugin Author TinyPNG

    (@tinypng)

    Hi,

    I’m sorry to read that you’re having problems with our plugin.
    I can understand that our plugin doesn’t work in combination with a plugin that renames images. Unfortunately, it is nearly impossible for a plugin to be compatible with all other plugins that have been created for WordPress.

    Our plugin stores the filenames of the files you add to WordPress in the database together with other metadata, such as information whether the image has already been compressed, and if so, for which images sizes. Our plugin then verifies the data stored in the database with the actual files on the filesystem, to make sure both are still in sync, and to check which images still need to be compressed.
    This part of the process fails in your case as the other plugin has renamed your images on the filesystem, so no image can be matched.

    Thread Starter jashaw

    (@jashaw)

    Thanks for your reply. I have been able to correct the issue. It would seem that the alternate image files in the metadata was the problem, not the image itself.
    I was able to correct the issue using the Regenerate Thumbnails plugin. That replaced the original images and the metadata.

    Your plugins is working fine now. I have not yet found the cause of the original metadata corruption but I don’t think it is this plugin that is to blame.

    Plugin Author TinyPNG

    (@tinypng)

    Thanks for the additional information. I’m very happy to hear that you’ve managed to fix the problem!

    Thread Starter jashaw

    (@jashaw)

    After a thorough investigation into what was causing this issue, here is what I found:
    The Media File Renamer, when renaming “.jpeg” files, was using .jpg for the original file name while using “.jpeg” for the thumbnail images. See the issue here.

    What this tells me about your plugin, is that you are not using the metadata to determine the file names used for thumbnails at some point in your code. While its hard to call this a bug, I think it is safe to say that it is a weakness. Changing the way you find those files would increase the stability of your plugin, especially with regard to conflicting with other plugins.

    Plugin Author TinyPNG

    (@tinypng)

    Hi,

    Thank you for getting back at us. I’ve taken a look as well, and I don’t think this incompatibility is caused by our plugin. I hope you can take the time to read my explanation.

    We do use the metadata that WordPress stores to identify images. Based on the filename stored within the WordPress metadata we know which file on the filesystem we need to compress.
    We use the “file” field stored in the metadata as described in the official documentation on https://codex.www.ads-software.com/Function_Reference/wp_get_attachment_metadata
    In case your interested in our source code, see line #50 in https://github.com/tinify/wordpress-plugin/blob/master/src/class-tiny-metadata.php

    This file field is not correctly updated by the Media File Renamer plugin.

    I’ve setup a basic WordPress install, with only the Media File Renamer plugin installed and enabled. When I add an image with a .jpeg extension, WordPress doesn’t change anything to the filename. It is in the metadata and the filesystem as a .jpeg. Then, when I click the “Auto Rename” button, it starts renaming the image and all additional image sizes, as intended by the plugin.
    All additional image sizes keep the same extension as you noticed (.jpeg), but the original image is renamed to receive the .jpg extension.

    This behaviour is of course a bit strange as I would expect all images to receive the same extension, but shouldn’t necessarily be a problem.
    However, not all references in the metadata are updated correctly. In this case, retrieving the “file” field from the image metadata returns an image with the extension .jpeg, while it should be .jpg, as the plugin has renamed the file on the filesystem.
    For all other image sizes this isn’t a problem, as they didn’t have their extension renamed as well.
    This is causing you to get “File does not exist” errors, as we can’t locate the original file for each image on your filesystem.

    I have quickly checked the source of the Media File Renamer plugin, and found the cause. The error is caused by line 917 in media-file-renamer.php which reads:

    $meta[‘file’] = $this->str_replace( $noext_old_filename, $noext_new_filename, $meta[‘file’] );

    Note the ‘noext’ parts. It updates the “file” field of the metadata, which is necessary, but it only replaces the part without the extension. Because it doesn’t update the metadata correctly, the data in the database in regards to the original image is no longer up to date with what’s on the filesystem.
    Any other WordPress plugin using the image metadata that’s stored in the database and needs to access the actual original file on the filesystem will run into the same kinds of problems that it can’t be accessed.

    I hope that explains everything in enough detail. I guess the best way forward is to address this with the Media File Renamer plugin author, and refer to this post. We’re happy to further assist if necessary.

    We would also certainly appreciate it if you could address your previous conclusions in regards to “bad programming” and “The plugin seems to be looking for a regex pattern to find files rather than querying the metadata”, as you mentioned in the support thread for the Media File Renamer plugin.
    We can surely understand your frustration in getting our plugin to work nicely in your WordPress installation, and also the time that you’ve spend investigating it, but those conclusions are simply not correct.

    Thanks!

    Thread Starter jashaw

    (@jashaw)

    Thanks for your further investigation. I wish everyone took as much pride in their work.

    Your test seems to be producing slightly different results than what I was observing on my system. In my case, the files themselves where still bearing the .jpeg extension, which is what lead me to assume that your plugin was not properly referencing the metadata for all file names. Unfortunately, I am not skilled enough with php to find errors in code, as you have done, so my observations were all I had to go on. Given a test on a clean install I cannot argue with your results since I cannot disable all of my plugins without adversely affecting our site. ( I hope that doesn’t mean I have another plugin issue yet to be flushed out.)

    Please accept my apologies for my incorrect conclusions. I will certainly update the support discussion with the Media File Renamer plugin.

    Thanks again for working on this.

    Plugin Author TinyPNG

    (@tinypng)

    You’re welcome! I’m happy to help ??

    In regards to your comment that we’re seeing different results, I think that they are actually the same. You mentioned: “The Media File Renamer, when renaming “.jpeg” files, was using .jpg for the original file name while using “.jpeg” for the thumbnail images.”

    That’s exactly the same thing that I’m seeing on a clean install. On the filesystem, the thumbnails (additional image sizes) are still having a .jpeg extension, while the original now has a .jpg extension.
    In the metadata in the database, the “file” field still has the .jpeg extension for the original image. It does however add a field called “url” to the metadata, which does have the correct extension (.jpg).

    I hope you can get everything sorted with the author of the Media File Renamer plugin. Do let us know if there’s anything we can help with.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Getting "Latest error: File does not exist" incorrectly’ is closed to new replies.