Opened 9 years ago
Last modified 6 years ago
#33278 new enhancement
Naming files with dimensions when manually cropping images
Reported by: | acbaile | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.1.6 |
Component: | Media | Keywords: | has-patch needs-refresh |
Focuses: | Cc: |
Description
Hi. When I create a new dimension for image file in image editor, I get file with random name. It is more useful to name it like basic files (filename-150x150.ext, filename-300x300.ext). I change for it "/wp-admin/includes/image-edit.php". This code first try to use dimension-name before using random. Starting from line 707. My code in a pluses.
// Generate new filename. $path = get_attached_file($post_id); $path_parts = pathinfo( $path ); $filename = $path_parts['filename']; $suffix = time() . rand(100, 999); //++++++++++++++++++++++++++++++++++++++++++++++++ // First try suffix-sizes - mine $suffix_sizes = $img->get_size(); $suffix_sizes = "-".$suffix_sizes["width"]."x".$suffix_sizes["height"]; //++++++++++++++++++++++++++++++++++++++++++++++++ if ( defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE && isset($backup_sizes['full-orig']) && $backup_sizes['full-orig']['file'] != $path_parts['basename'] ) { if ( 'thumbnail' == $target ) $new_path = "{$path_parts['dirname']}/{$filename}-temp.{$path_parts['extension']}"; else $new_path = $path; } else { //++++++++++++++++++++++++++++++++++++++++++++++++ // First try suffix-sizes - mine $filename = preg_replace( "/-e([0-9]+)$/", "", $filename ); $filename = preg_replace( "/-([0-9]{1,5})x([0-9]{1,5})$/", "", $filename ); $filename .= $suffix_sizes; $new_filename = $filename.".".$path_parts["extension"]; $new_path = $path_parts["dirname"]."/".$new_filename; if ( file_exists($new_path) ){ //++++++++++++++++++++++++++++++++++++++++++++++++ while( true ) { $filename = preg_replace( '/-e([0-9]+)$/', '', $filename ); $filename .= "-e{$suffix}"; $new_filename = "{$filename}.{$path_parts['extension']}"; $new_path = "{$path_parts['dirname']}/$new_filename"; if ( file_exists($new_path) ) $suffix++; else break; } //++++++++++++++++++++++++++++++++++++++++++++++++ } //++++++++++++++++++++++++++++++++++++++++++++++++ }
Attachments (2)
Change History (7)
#3
follow-up:
↓ 4
@
9 years ago
- Keywords needs-refresh added
- Summary changed from Naming files with dimensions in the name (/wp-admin/includes/image-edit.php) to Naming files with dimensions when manually cropping images
Hey there, thanks for your report!
Please have a look at the handbook on how to create proper patch files.
Can you elaborate on why this behaviour should be changed?
As far as I can tell, a random hash is generated on purpose because it shouldn't conflict with already existing images.
#4
in reply to:
↑ 3
@
9 years ago
Replying to swissspidy:
Can you elaborate on why this behaviour should be changed?
Main reason. I use fancybox, and when I want to place in a post static image with smaller size, I need to go to the image editor, I create smaller size, and then I need put name of this file in a post. But I don't know it. I need to open ftp-client to see and copy this name. It very long and difficult way. When naming is by dimension I can simply write it by keyboard.
/wp-admin/includes/image-edit.php