Git Product home page Git Product logo

Comments (11)

respondcreate avatar respondcreate commented on July 17, 2024

Hey @Bartvds !

That's a super-fantastic idea! I've been less-than-thrilled with how long file names can get and a hashing function would be the ideal way to do it for sure.

I'm adding this to the roadmap right now...thanks for the suggestion!!

Otherwise, how's the app been performing for you?

from django-versatileimagefield.

mrgaolei avatar mrgaolei commented on July 17, 2024

+1

I recommend using file's md5 hash to make their's filename.

from django-versatileimagefield.

Bartvds avatar Bartvds commented on July 17, 2024

@respondcreate Sorry for my late reply. DVIF app works very well for us, thanks for publishing it.

@mrgaolei A combination of these would be nice: a hash of the content of the original image as a filename, and a hash of the DVIF options as postfix. This would also cut-down duplication of re-uploaded images (our content people occasionally re-use same image files in different fields).

Ideally encode the hash as base32 to trim down the length compared to base16 (hex). We use the lowercase crockford base32 alphabet for nice friendly hashes.

Not sure how far this should be implemented. Maybe if there is too much choices some optional callbacks to process the names would work best (with a sane default of course).

from django-versatileimagefield.

respondcreate avatar respondcreate commented on July 17, 2024

Hey @Bartvds

I'm going to tackle this feature this weekend, would you mind linking me to a gist (or commit or whatever) with an example function that accepts a string and spits out a 'lowercase crockford base32' string trimmed to a base16 hex length? I already know where in the code the custom hashing functions should be injected so having an example off which to base the first function would go a long way to having this happen sooner rather than later.

Thanks in advance!

from django-versatileimagefield.

fabiocaccamo avatar fabiocaccamo commented on July 17, 2024

Any news about this feature?
I think that also quality should be included in the image_key
+1

from django-versatileimagefield.

fabiocaccamo avatar fabiocaccamo commented on July 17, 2024

Check my PR

from django-versatileimagefield.

respondcreate avatar respondcreate commented on July 17, 2024

Thanks for your PR @fabiocaccamo , I'm working on integrating it right now. Stay tuned!

from django-versatileimagefield.

Bartvds avatar Bartvds commented on July 17, 2024

@respondcreate I think the hashing callback could be a simple string->string function. DVIF loads it from dotted path (django import_utils) and calls it with the regular long name and it returns a replacement string.

I would hash the unicode string to bytes with sha1 or maybe even md5 and put those through a nice looking encoder. Possibly trim it before or after (not sure if good idea), maybe strip() the fill character ('=' usually).

Base16 (ye olde hexdigest()), base32 (possibly with crockfords characters) and base58 all give decent looking utf characters for the hash bytes. I would lowercase base16 and base32 for cosmetics effect.

from django-versatileimagefield.

respondcreate avatar respondcreate commented on July 17, 2024

Hey @Bartvds, @mrgaolei and @fabiocaccamo

This feature has been added in the 1.4 release by way of the new VERSATILEIMAGEFIELD_SETTINGS['image_key_post_processor'] setting. Just upgrade via pip to start using it:

$ pip install django-versatileimagefield==1.4

NOTE: The 1.4 release dropped support for Django 1.5.x and 1.6.x

from django-versatileimagefield.

Bartvds avatar Bartvds commented on July 17, 2024

@respondcreate Thanks. We've been running this in production for a few days and it works great so far.

from django-versatileimagefield.

respondcreate avatar respondcreate commented on July 17, 2024

@Bartvds Glad it's working out well! Don't hesitate to file a ticket if you run into anything strange.

from django-versatileimagefield.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.