We use sorl-thumbnail for scaling images by keeping the original one intact. Sorl proven to be a great tool for generating different sized images throughout the website.
I presume that you know how to use sorl-thumbnail. Here we see how to preserve filename.
Search Engines will give importance to image alt tag content but it definitely has some impact on relevant image file name too.
Sorl will generate random names for the thumbnails it will create and as of now, there is no default setting to preserve filename in generating thumbnails. It is possible to have the same name for different sized images as sorl will create thumbnails in random folders, so, there will be no conflict in names.
We must override the thumbnail backend. So provide
Now we should create the class that returns our custom filenames.
# thumbnailname.py from sorl.thumbnail.base import ThumbnailBackend, EXTENSIONS from sorl.thumbnail.conf import settings from sorl.thumbnail.helpers import tokey, serialize import os.path class SEOThumbnailBackend(ThumbnailBackend): def _get_thumbnail_filename(self, source, geometry_string, options): """ Computes the destination filename. """ key = tokey(source.key, geometry_string, serialize(options)) filename, _ext = os.path.splitext(os.path.basename(source.name)) path = '%s/%s' % (key, filename) return '%s%s.%s' % (settings.THUMBNAIL_PREFIX, path, EXTENSIONS[options['format']])
It’s important to keep source key or else there will be an issue of different images with same names, so we should create a folder with source key and save the file with our custom name.
'micropyramid.png' is stored as THUMBNAIL_PREFIX/source_key/micropyramid.png.
Micropyramid is a software development and cloud consulting partner for enterprise businesses across the world. We work on python, Django, Salesforce, Angular, Reactjs, React Native, MySQL, PostgreSQL, Docker, Linux, Ansible, git, amazon web services. We are Amazon and salesforce consulting partner with 5 years of cloud architect experience. We develop e-commerce, retail, banking, machine learning, CMS, CRM web and mobile applications.
Django-CRM :Customer relationship management based on Django
Django-blog-it : django blog with complete customization and ready to use with one click installer Edit
Django-webpacker : A django compressor tool
Django-MFA : Multi Factor Authentication
Docker-box : Web Interface to manage full blown docker containers and imagesMore...