Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding ability to custom format filename of generated thumbnails

  • Loading branch information...
commit b58843b62914af7c8c413933915e609b2f6c87e8 1 parent 65d3fa6
@dongilbert authored
Showing with 15 additions and 4 deletions.
  1. +15 −4 libraries/joomla/image/image.php
View
19 libraries/joomla/image/image.php
@@ -214,9 +214,13 @@ public function generateThumbs($thumbSizes, $creationMethod = self::SCALE_INSIDE
* Method to create thumbnails from the current image and save them to disk. It allows creation by resizing
* or croppping the original image.
*
- * @param mixed $thumbSizes string or array of strings. Example: $thumbSizes = array('150x75','250x150');
+ * @param mixed $thumbSizes String or array of strings. Example: $thumbSizes = array('150x75','250x150');
* @param integer $creationMethod 1-3 resize $scaleMethod | 4 create croppping
- * @param string $thumbsFolder destination thumbs folder. null generates a thumbs folder in the image folder
+ * @param string $thumbsFolder Destination thumbs folder. null generates a thumbs folder in the image folder
+ * @param string $format Filename format for the thumbnails to be saved to. Exclude extension from the format.
+ * {filename} - This will hold the files original name.
+ * {width} - This will hold the thumbnail width.
+ * {height} - This will hold the thumbnail height.
*
* @return array
*
@@ -225,7 +229,7 @@ public function generateThumbs($thumbSizes, $creationMethod = self::SCALE_INSIDE
*
* @since 12.2
*/
- public function createThumbs($thumbSizes, $creationMethod = self::SCALE_INSIDE, $thumbsFolder = null)
+ public function createThumbs($thumbSizes, $creationMethod = self::SCALE_INSIDE, $thumbsFolder = null, $format = '{filename}_{width}x{height}')
{
// Make sure the resource handle is valid.
if (!$this->isLoaded())
@@ -233,6 +237,12 @@ public function createThumbs($thumbSizes, $creationMethod = self::SCALE_INSIDE,
throw new LogicException('No valid image was loaded.');
}
+ // Ensure that the filename format includes our required variables.
+ if (strpos($format, '{filename}') === false || strpos($format, '{width}') === false || strpos($format, '{height}') === false)
+ {
+ throw new InvalidArgumentException('Requested filename format is invalid. ' . $format);
+ }
+
// No thumbFolder set -> we will create a thumbs folder in the current image folder
if (is_null($thumbsFolder))
{
@@ -262,7 +272,8 @@ public function createThumbs($thumbSizes, $creationMethod = self::SCALE_INSIDE,
// Generate thumb name
$filename = pathinfo($this->getPath(), PATHINFO_FILENAME);
$fileExtension = pathinfo($this->getPath(), PATHINFO_EXTENSION);
- $thumbFileName = $filename . '_' . $thumbWidth . 'x' . $thumbHeight . '.' . $fileExtension;
+ $tmpName = str_replace(array('{filename}', '{width}', '{height}'), array($filename, $thumbWidth, $thumbHeight), $format);
+ $thumbFileName = $tmpName . '.' . $fileExtension;
// Save thumb file to disk
$thumbFileName = $thumbsFolder . '/' . $thumbFileName;
Please sign in to comment.
Something went wrong with that request. Please try again.