Skip to content

Commit

Permalink
fix name-change to scaled
Browse files Browse the repository at this point in the history
  • Loading branch information
Volkmar Kantor committed Dec 13, 2019
1 parent 3626b7d commit d4151d8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
18 changes: 11 additions & 7 deletions functions/save.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function saveThumbnail() {

$croppedSize = self::getCroppedSize($activeImageSize,$imageMetadata,$input);

$currentFilePath = self::generateFilename($sourceImgPath, $croppedSize['width'], $croppedSize['height'], $activeImageSize->crop);
$currentFilePath = self::generateFilename($sourceImgPath, $imageMetadata, $croppedSize['width'], $croppedSize['height'], $activeImageSize->crop);
self::addDebug("filename: ".$currentFilePath);
$currentFilePathInfo = pathinfo($currentFilePath);
$currentFilePathInfo['basename'] = wp_basename($currentFilePath);//uses the i18n version of the file-basename
Expand Down Expand Up @@ -325,20 +325,24 @@ protected function getValidatedInput() {
/**
* Generate the Filename (and path) of the thumbnail based on width and height the same way as WordPress do.
* @see generate_filename in wp-includes/class-wp-image-editor.php
* @param string Path to the original (full-size) file.
* @param int width of the new image
* @param int height of the new image
* @param boolean crop is this a cropped image-size
* @param string $file Path to the original (full-size) file.
* @param array $imageMetadata the WordPress image-metadata array
* @param int $width width of the new image
* @param int $height height of the new image
* @param boolean $crop is this a cropped image-size
* @return string path to the new image
*/
protected static function generateFilename( $file, $w, $h, $crop ){
protected static function generateFilename( $file, $imageMetadata, $w, $h, $crop ){
$info = pathinfo($file);
$dir = $info['dirname'];
$ext = $info['extension'];
$name = wp_basename($file, '.'.$ext);
if(!empty($imageMetadata['original_image'])) {
$name = wp_basename($imageMetadata['original_image'], '.'.$ext);
}
$suffix = $w.'x'.$h;
$destfilename = $dir.'/'.$name.'-'.$suffix.'.'.$ext;
return apply_filters('crop_thumbnails_filename', $destfilename, $file, $w, $h, $crop, $info);
return apply_filters('crop_thumbnails_filename', $destfilename, $file, $w, $h, $crop, $info, $imageMetadata);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Parameters:
* `$w` - The width of the thumbnail size
* `$h` - The height of the thumbnail size
* `$crop` - If true the thumbnail size is cropped

* `$imageMetadata` - The Wordpress image-metadata array (added in version 1.2.6)


### FILTER `crop_thumbnails_before_update_metadata`
Expand Down
3 changes: 2 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ If you fork and planning to publish the forked plugin, please contact me.
= 1.2.6 =
* update dependencies
* fix typo

* fix a bug where the image name of the thumbnail changed to "imagename-scaled-..." cause of the new features of WordPress 5.3
* extend the filter "crop_thumbnails_filename" by the image-metadata-array

= 1.2.5 =
* fix a bug that may occure on utf8-filenames
Expand Down

0 comments on commit d4151d8

Please sign in to comment.