Disable image renaming

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
7 years ago
Hello,

Does anyone know how to disable the automatic image renaming?

When an image is uploaded it takes the name of the product plus some identification numbers.

I just need the original name to remain intact.

Thanks.


PS: I do not talk about the title/alt options.
7 years ago
izybit wrote:
When an image is uploaded it takes the name of the product plus some identification numbers.

When images are set to store in the file system and a new image is uploaded through the admin interface it gets renamed to the id of the newly created record in the Picture table with _0 appended on the end. You can see these images in the \Content\Images folder of your website. This renaming process ensures that all image names are unique and prevents nop from having to deal with what happens if the user tries to upload images with filenames that already exist. It does however make reusing the same image across multiple products very difficult.

I think you're talking about the images in the \Content\Images\Thumbs folder. These images are generated on demand by the function in the picture service that generates the image URLs that are used in the src attribute of the img tags in the website. These are named by taking the image id, appending an seo friendly version of the  product name (localised for the current language), then appending the thumbnail dimension. You can see that these are created on demand by renaming a product and seeing that new thumbnails will be generated next time you browse to it. Similarly you can just delete all these images and they'll be regenerated when required (though it's extremely memory and processor intensive to create the thumbnails so not necessarily a good idea if you have thousands of images).

izybit wrote:
Does anyone know how to disable the automatic image renaming?

I just need the original name to remain intact.

With images set to store in the file system the only link that exists back to the record in the Picture table is the fact that the filename includes the image id. This makes it difficult to retain the original file name as you suggest because there isn't currently anywhere in the Picture table to store it. You'd have to add an additional column to the Picture table and associated Picture entity to store the filename and then update the functions in the PictureService to use that filename instead of the image id to locate the images on disk. You'd also have to work out some method of handling duplicate filenames, though this could be as simple as overwriting them or warning the user.

So yeah, it's possible with a bit of customisation but there isn't a setting in the admin site for it.
7 years ago
Thanks for the answer Pete.

Our filenames are already too descriptive (because we, our clients, and search engines rely on them) and I do not want them butchered when uploaded to the website (for example, renaming an image with shirt sizes to "White Cotton Shirt" is just too stupid).

Since every uploaded image takes a name starting with the id of the Picture table I really do not see how one can end up with two images having the same name since the id is always unique.
You can literally upload the same image a million times and you will end up with a million different filenames.

Likewise, when generating the thumbs you have the unique id in front of everything (and the dimension at the end) which guarantees the uniqueness of the filenames.

So, ending up with two images having the same name is not really possible.

Also, you are correct to assume that I am talking about the images stored in the \Thumbs folder because those are displayed on the website and they are the ones that affect our SEO, brand awareness, (re)use of files, etc.

Anyhow, since the database has a place to store the SeoFilename, AltAttribute and TitleAttribute (in .Picture) I don't think it would be that difficult to store the original file name next to them.

But, since the nop team hasn't added that to the db, and for the sake of simplicity, I think an easier solution would be to use the TitleAttribute or AltAttribute instead of the SeoFilename to generate the image thumb names and just put the original filename as Title/Alt for every image added to products.

Does the above approach has any drawbacks I cannot think off?
7 years ago
izybit wrote:
Since every uploaded image takes a name starting with the id of the Picture table I really do not see how one can end up with two images having the same name since the id is always unique.
You can literally upload the same image a million times and you will end up with a million different filenames.

Likewise, when generating the thumbs you have the unique id in front of everything (and the dimension at the end) which guarantees the uniqueness of the filenames.

So, ending up with two images having the same name is not really possible.

I thought that was the point I just made. You asked if it was possible to keep the filename intact when uploading the images which is what could lead to the possibility of name clashes.
7 years ago
petemitch wrote:
I thought that was the point I just made. You asked if it was possible to keep the filename intact when uploading the images which is what could lead to the possibility of name clashes.

To clarify, I am not talking about omitting the ids from the start and end of the filename, just keeping the original filename and adding the required ids so the image thumb will have a name like 000005_original-descriptive-filename-not-some-random-seofilename_550.jpeg
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.