Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: prefix generated filenames #1427

Closed
mgussekloo opened this issue May 22, 2017 · 1 comment
Closed

Suggestion: prefix generated filenames #1427

mgussekloo opened this issue May 22, 2017 · 1 comment

Comments

@mgussekloo
Copy link

mgussekloo commented May 22, 2017

Generated filenames using the 'resize' filter are generally filename_[width]x[height].jpg. This makes it hard to tell them apart from "original" files in the uploads-folder.

I made a filter called 'prefix' that prefixes a filename. I use it to rename all my resized files, so they are 'resized_filename_widthxheight.jpg'.

I was wondering if anyone would find this useful. It might be standard behavior of the resize-filter.

 $twig->addFilter('prefix', new Twig_Filter_Function(function($src, $prefix) {
	        $oldFile = ABSPATH . TimberURLHelper::get_rel_url($src);
	        $newFilename = dirname($oldFile) . '/' . $prefix . basename($oldFile);
	        if (file_exists($oldFile) && !is_dir($oldFile) && !file_exists($newFilename)) {
	            rename($oldFile, $newFilename);
	        }
	        $newSrc = dirname($src) . '/' . $prefix . basename($oldFile);
                return $newSrc;
  }));
@nlemoine
Copy link
Member

nlemoine commented Mar 6, 2023

@gchtr I also think Timber resized images should live outside the uploads folder (I'm actually dosing this in my own Timber implementation) but let's discuss this when we'll be replacing the image resize part from Timber :)

@nlemoine nlemoine closed this as completed Mar 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants