silverstripe / silverstripe-assets

Silverstripe Assets component
BSD 3-Clause "New" or "Revised" License
9 stars 67 forks source link

Manipulated Images filename suffix #210

Open JorisDebonnet opened 5 years ago

JorisDebonnet commented 5 years ago

Filenames get a suffix based on the manipulation that happened on them. I remember changing that at some point in the 3.x line so that they were put into folders instead while keeping the original filename, but I guess that missed the transition into 4.x.

Anyhow, the current system even creates filenames such as WhatsApp-Image-2018-11-24-at-20__FillMaxWzk2MCw2MDBd.17.06-4.jpeg. I think at least that should be fixed: the suffix should come before the last dot (if anywhere in the filename), not the first one, e.g. becoming WhatsApp-Image-2018-11-24-at-20.17.06-4__FillMaxWzk2MCw2MDBd.jpeg instead.

(In 3.x, it would be placed into FillMaxWzk2MCw2MDBd / WhatsApp-Image-2018-11-24-at-20.17.06-4.jpeg)

maxime-rainville commented 5 years ago

I'm not sure there's an objective way to pick those filenames that will please everyone.

If you really need to be able to customise those generated filenames, you might be able to do it by extending FlysystemAssetStore and overriding getFileID() with your own method.

Then you would be able to inject your own custom AssetStore with something like this:

SilverStripe\Core\Injector\Injector:
  SilverStripe\Assets\Storage\AssetStore:
    class: JorisDebonnet\YourPrettyGeneratedFilenameAssetStore
    properties:
      PublicFilesystem: '%$League\Flysystem\Filesystem.public'
      ProtectedFilesystem: '%$League\Flysystem\Filesystem.protected'

I haven't tried this, so I got no clue if it would actually work.

JorisDebonnet commented 5 years ago

I realize it may be a bit ambitious to suggest changing the filenames entirely, but this issue is mostly about the bug mentioned in the second paragraph of my original post: filenames such as one.two.jpg are changed into one__FillMaxblahblah.two.jpg, while it should at least be one.two__FillMaxblahblah.jpg, no?

And then at a later stage we could maybe argue about what would be the best default format for filenames for manipulated images 😋 (But thank you already for the suggestion on how to customize this in a specific project)

sb-relaxt-at commented 2 years ago

From my point of view this is a bug as it seems to be a precondition that the file is built like this: "originalname__variant.extension", e.g.: https://github.com/silverstripe/silverstripe-assets/blob/1/src/FilenameParsing/HashFileIDHelper.php#L85

When having a file name with a dot, it is no longer possible to parse the file name and determine the original filename.