From a31fa1b1d276873e749f805f7ba9688f7d2b5e6b Mon Sep 17 00:00:00 2001 From: Jack Wilkinson Date: Wed, 6 Jul 2022 04:07:38 +0100 Subject: [PATCH 1/3] Added lazy resizing support for thumbnail view in media manager --- modules/backend/widgets/MediaManager.php | 32 ++++++++++++++----- .../mediamanager/partials/_item-icon.php | 23 ++++++------- .../partials/_thumbnail-image.php | 4 +-- 3 files changed, 36 insertions(+), 23 deletions(-) diff --git a/modules/backend/widgets/MediaManager.php b/modules/backend/widgets/MediaManager.php index ea29929c09..2648fc9ca0 100644 --- a/modules/backend/widgets/MediaManager.php +++ b/modules/backend/widgets/MediaManager.php @@ -802,7 +802,7 @@ public function onResizeImage() $path = Input::get('path'); $path = MediaLibrary::validatePath($path); - $croppedPath = $this->resizeImage(MediaLibrary::url($path), [ + $croppedPath = $this->resizeImage($path, [ 'mode' => 'exact', 'width' => $width, 'height' => $height @@ -1325,14 +1325,14 @@ protected function generateThumbnail($thumbnailInfo, $thumbnailParams = null): a /* * Resize the thumbnail and save to the thumbnails directory */ - $fullThumbnailPath = $this->resizeImage(MediaLibrary::url($path), $thumbnailParams); + $fullThumbnailPath = $this->lazyResizeImage($path, $thumbnailParams); /* * Delete the temporary file */ $markup = $this->makePartial('thumbnail-image', [ 'isError' => false, - 'imageUrl' => $this->getThumbnailImageUrl($fullThumbnailPath) + 'imageUrl' => $fullThumbnailPath ]); } catch (\Throwable $ex) { $markup = $this->makePartial('thumbnail-image', ['isError' => true]); @@ -1353,10 +1353,26 @@ protected function generateThumbnail($thumbnailInfo, $thumbnailParams = null): a /** * Resize an image */ - protected function resizeImage(string $image, array $params): string + protected function lazyResizeImage(string $path, array $params): string + { + return ImageResizer::filterGetUrl( + MediaLibrary::url($path), + $params['width'], + $params['height'], + array_merge( + ['mode' => 'exact'], + $params + ) + ); + } + + /** + * Resize an image + */ + protected function resizeImage(string $path, array $params): string { return ImageResizer::processImage( - $image, + MediaLibrary::url($path), $params['width'], $params['height'], array_merge( @@ -1370,10 +1386,10 @@ protected function resizeImage(string $image, array $params): string /** * Crop an image */ - protected function cropImage(string $image, array $params): string + protected function cropImage(string $path, array $params): string { return ImageResizer::processImage( - $image, + MediaLibrary::url($path), $params['width'], $params['height'], array_merge( @@ -1423,7 +1439,7 @@ protected function getCropEditImageUrlAndSize($path, $params = null) $url = MediaLibrary::url($path); if ($params) { - $url = $this->resizeImage($url, [ + $url = $this->resizeImage($path, [ 'mode' => 'exact', 'width' => $params['width'], 'height' => $params['height'], diff --git a/modules/backend/widgets/mediamanager/partials/_item-icon.php b/modules/backend/widgets/mediamanager/partials/_item-icon.php index 6b9f05df42..c974362ab5 100644 --- a/modules/backend/widgets/mediamanager/partials/_item-icon.php +++ b/modules/backend/widgets/mediamanager/partials/_item-icon.php @@ -1,26 +1,23 @@
- - thumbnailExists($thumbnailParams, $item->path, $item->lastModified); - ?> - + lazyResizeImage($item->path, $thumbnailParams) + ): ?>
makePartial('thumbnail-image', [ - 'isError' => $this->thumbnailIsError($thumbnailPath), - 'imageUrl' => $this->getThumbnailImageUrl($thumbnailPath) + 'imageUrl' => $thumbnailPath ]) ?>
diff --git a/modules/backend/widgets/mediamanager/partials/_thumbnail-image.php b/modules/backend/widgets/mediamanager/partials/_thumbnail-image.php index 6e32df95b4..142c762b4e 100644 --- a/modules/backend/widgets/mediamanager/partials/_thumbnail-image.php +++ b/modules/backend/widgets/mediamanager/partials/_thumbnail-image.php @@ -1,6 +1,6 @@ - +

- \ No newline at end of file + From 585949abc4fc9295bfc48c7acbd96dfebd1a3521 Mon Sep 17 00:00:00 2001 From: Luke Towers Date: Wed, 6 Jul 2022 14:42:34 -0600 Subject: [PATCH 2/3] Code review Removed a bunch of thumbnail generation related methods that are no longer required now that the ImageResizer class handles it all. --- modules/backend/widgets/MediaManager.php | 418 ++++++------------ .../assets/images/broken-thumbnail.gif | Bin 1097 -> 0 bytes .../assets/js/mediamanager-browser-min.js | 3 +- .../assets/js/mediamanager.imagecroppopup.js | 2 - .../mediamanager/partials/_item-icon.php | 19 +- modules/system/classes/ImageResizer.php | 27 -- 6 files changed, 142 insertions(+), 327 deletions(-) delete mode 100644 modules/backend/widgets/mediamanager/assets/images/broken-thumbnail.gif diff --git a/modules/backend/widgets/MediaManager.php b/modules/backend/widgets/MediaManager.php index 2648fc9ca0..74d40688fe 100644 --- a/modules/backend/widgets/MediaManager.php +++ b/modules/backend/widgets/MediaManager.php @@ -43,11 +43,6 @@ class MediaManager extends WidgetBase const FILTER_EVERYTHING = 'everything'; - /** - * @var string Hash string for the broken image graphic. - */ - protected $brokenImageHash; - /** * @var boolean Determines whether the widget is in readonly mode or not. */ @@ -121,9 +116,8 @@ public function render() /** * Perform search AJAX handler - * @return array */ - public function onSearch() + public function onSearch(): array { $this->setSearchTerm(Input::get('search')); @@ -137,9 +131,8 @@ public function onSearch() /** * Change view AJAX handler - * @return array */ - public function onGoToFolder() + public function onGoToFolder(): array { $path = Input::get('path'); @@ -162,13 +155,12 @@ public function onGoToFolder() /** * Generate thumbnail AJAX handler - * @return array */ - public function onGenerateThumbnails() + public function onGenerateThumbnails(): array { $batch = Input::get('batch'); if (!is_array($batch)) { - return; + return []; } $result = []; @@ -183,9 +175,10 @@ public function onGenerateThumbnails() /** * Get thumbnail AJAX handler - * @return array + * + * @throws ApplicationException if the lastModified date is invalid */ - public function onGetSidebarThumbnail() + public function onGetSidebarThumbnail(): array { $path = MediaLibrary::validatePath(Input::get('path')); $lastModified = Input::get('lastModified'); @@ -209,9 +202,8 @@ public function onGetSidebarThumbnail() /** * Set view preference AJAX handler - * @return array */ - public function onChangeView() + public function onChangeView(): array { $viewMode = Input::get('view'); $path = Input::get('path'); @@ -230,9 +222,8 @@ public function onChangeView() /** * Set filter preference AJAX handler - * @return array */ - public function onSetFilter() + public function onSetFilter(): array { $filter = Input::get('filter'); $path = Input::get('path'); @@ -251,9 +242,8 @@ public function onSetFilter() /** * Set sorting preference AJAX handler - * @return array */ - public function onSetSorting() + public function onSetSorting(): array { $sortBy = Input::get('sortBy', $this->getSortBy()); $sortDirection = Input::get('sortDirection', $this->getSortDirection()); @@ -273,9 +263,11 @@ public function onSetSorting() /** * Delete library item AJAX handler - * @return array + * + * @throws ApplicationException if the paths input is invalid + * @todo Move media events to the MediaLibary class instead. */ - public function onDeleteItem() + public function onDeleteItem(): array { $this->abortIfReadOnly(); @@ -301,6 +293,7 @@ public function onDeleteItem() * Add to bulk collection */ $filesToDelete[] = $path; + } elseif ($type === MediaLibraryItem::TYPE_FOLDER) { /* * Delete single folder @@ -369,9 +362,8 @@ public function onDeleteItem() /** * Show rename item popup AJAX handler - * @return array */ - public function onLoadRenamePopup() + public function onLoadRenamePopup(): array { $this->abortIfReadOnly(); @@ -387,10 +379,12 @@ public function onLoadRenamePopup() } /** - * Reanem library item AJAX handler - * @return array + * Rename library item AJAX handler + * + * @throws ApplicationException if the new name is invalid + * @todo Move media events to the MediaLibary class instead. */ - public function onApplyName() + public function onApplyName(): array { $this->abortIfReadOnly(); @@ -470,9 +464,10 @@ public function onApplyName() /** * Create library folder AJAX handler - * @return array + * + * @throws ApplicationException If the requested folder already exists or is otherwise invalid */ - public function onCreateFolder() + public function onCreateFolder(): array { $this->abortIfReadOnly(); @@ -533,9 +528,10 @@ public function onCreateFolder() /** * Show move item popup AJAX handler - * @return array + * + * @throws ApplicationException If the exclude input data is not an array */ - public function onLoadMovePopup() + public function onLoadMovePopup(): array { $this->abortIfReadOnly(); @@ -568,9 +564,10 @@ public function onLoadMovePopup() /** * Move library item AJAX handler - * @return array + * + * @throws ApplicationException if the input data is invalid */ - public function onMoveItems() + public function onMoveItems(): array { $this->abortIfReadOnly(); @@ -659,20 +656,18 @@ public function onMoveItems() /** * Sidebar visibility AJAX handler - * @return array */ - public function onSetSidebarVisible() + public function onSetSidebarVisible(): void { - $visible = Input::get('visible'); + $visible = (bool) Input::get('visible'); $this->setSidebarVisible($visible); } /** - * Start image cropping session AJAX handler - * @return array + * Renders the widget in a popup body */ - public function onLoadPopup() + public function onLoadPopup(): string { $this->bottomToolbar = Input::get('bottomToolbar', $this->bottomToolbar); @@ -682,8 +677,7 @@ public function onLoadPopup() } /** - * Load image for cropping AJAX handler - * @return string + * Prepares & renders the image crop popup body */ public function onLoadImageCropPopup(): string { @@ -693,35 +687,31 @@ public function onLoadImageCropPopup(): string $path = MediaLibrary::validatePath($path); $selectionParams = $this->getSelectionParams(); - $urlAndSize = $this->getCropEditImageUrlAndSize($path); - $width = $urlAndSize['dimensions'][0]; - $height = $urlAndSize['dimensions'][1] ?: 1; + $url = MediaLibrary::url($path); + $dimensions = Str::startsWith($url, '/') + ? getimagesize(base_path($url)) + : getimagesize($url); + + $width = $dimensions[0]; + $height = $dimensions[1] ?: 1; $this->vars['currentSelectionMode'] = $selectionParams['mode']; $this->vars['currentSelectionWidth'] = $selectionParams['width']; $this->vars['currentSelectionHeight'] = $selectionParams['height']; - $this->vars['imageUrl'] = $urlAndSize['url']; - $this->vars['dimensions'] = $urlAndSize['dimensions']; + $this->vars['imageUrl'] = $url; + $this->vars['dimensions'] = $dimensions; $this->vars['originalRatio'] = round($width / $height, 5); $this->vars['path'] = $path; return $this->makePartial('image-crop-popup-body'); } - /** - * End crop session AJAX handler - * @return array - */ - public function onEndCroppingSession() - { - $this->abortIfReadOnly(); - } - /** * Crop image AJAX handler - * @return array + * + * @throws ApplicationException if the input data is invalid */ - public function onCropImage() + public function onCropImage(): array { $this->abortIfReadOnly(); @@ -745,14 +735,25 @@ public function onCropImage() throw new ApplicationException('You must define a crop size before inserting'); } - $croppedPath = $this->cropImage($sourceImageUrl, [ - 'height' => $selectionData['h'], - 'width' => $selectionData['w'], - 'offset' => [ - $selectionData['x'], - $selectionData['y'], + // Initialize the ImageResizer + $resizer = new ImageResizer( + $sourceImageUrl, + $selectionData['w'], + $selectionData['h'], + [ + 'mode' => 'exact', + 'offset' => [ + $selectionData['x'], + $selectionData['y'], + ], ], - ]); + ); + + // Crop the image + $resizer->crop(); + + // Get the path to the cropped image + $croppedPath = $resizer->getPathToResizedImage(); // Generate the target path for the cropped image $targetPath = $this->deduplicatePath($mediaItemPath, '_cropped'); @@ -782,10 +783,13 @@ public function onCropImage() } /** - * Resize image AJAX handler - * @return array + * Handles resizing the provided image and returns the URL to the resized image + * Used by the Crop & Insert popup to resize the image being cropped on the canvas + * before cropping it. + * + * @throws ApplicationException if the provided input data is invalid */ - public function onResizeImage() + public function onResizeImage(): array { $this->abortIfReadOnly(); @@ -802,14 +806,24 @@ public function onResizeImage() $path = Input::get('path'); $path = MediaLibrary::validatePath($path); - $croppedPath = $this->resizeImage($path, [ - 'mode' => 'exact', - 'width' => $width, - 'height' => $height - ]); + // Initialize the ImageResizer + $resizer = new ImageResizer( + MediaLibrary::url($path), + $width, + $height, + [ + 'mode' => 'exact', + ], + ); + + // Process the resize + $resizer->resize(); + + // Get the URL to the resized image + $resizedUrl = $resizer->getResizedUrl(); return [ - 'url' => $this->getThumbnailImageUrl($croppedPath), + 'url' => $resizedUrl, 'dimensions' => [$width, $height] ]; } @@ -820,7 +834,6 @@ public function onResizeImage() /** * Internal method to prepare view variables. - * @return array */ protected function prepareVars() { @@ -856,10 +869,11 @@ protected function prepareVars() /** * Returns a list of folders and files in a Library folder. + * * @param string $searchTerm * @param string $filter * @param string $sortBy - * @param array[System\Classes\MediaLibraryItem] + * @return array[System\Classes\MediaLibraryItem] */ protected function listFolderItems($folder, $filter, $sortBy) { @@ -871,10 +885,11 @@ protected function listFolderItems($folder, $filter, $sortBy) /** * Finds files from within the media library based on supplied criteria, * returns an array of MediaLibraryItem objects. + * * @param string $searchTerm * @param string $filter * @param string $sortBy - * @param array[System\Classes\MediaLibraryItem] + * @return array[System\Classes\MediaLibraryItem] */ protected function findFiles($searchTerm, $filter, $sortBy) { @@ -885,10 +900,10 @@ protected function findFiles($searchTerm, $filter, $sortBy) /** * Sets the user current folder from the session state + * * @param string $path - * @return void */ - protected function setCurrentFolder($path) + protected function setCurrentFolder($path): void { $path = MediaLibrary::validatePath($path); @@ -897,6 +912,7 @@ protected function setCurrentFolder($path) /** * Gets the user current folder from the session state + * * @return string */ protected function getCurrentFolder() @@ -906,10 +922,10 @@ protected function getCurrentFolder() /** * Sets the user filter from the session state + * * @param string $filter - * @return void */ - protected function setFilter($filter) + protected function setFilter($filter): void { if (!in_array($filter, [ self::FILTER_EVERYTHING, @@ -926,6 +942,7 @@ protected function setFilter($filter) /** * Gets the user filter from the session state + * * @return string */ protected function getFilter() @@ -935,16 +952,17 @@ protected function getFilter() /** * Sets the user search term from the session state + * * @param string $searchTerm - * @return void */ - protected function setSearchTerm($searchTerm) + protected function setSearchTerm($searchTerm): void { $this->putSession('media_search', trim($searchTerm)); } /** * Gets the user search term from the session state + * * @return string */ protected function getSearchTerm() @@ -954,10 +972,10 @@ protected function getSearchTerm() /** * Sets the user sort column from the session state + * * @param string $sortBy - * @return void */ - protected function setSortBy($sortBy) + protected function setSortBy($sortBy): void { if (!in_array($sortBy, [ MediaLibrary::SORT_BY_TITLE, @@ -972,6 +990,7 @@ protected function setSortBy($sortBy) /** * Gets the user sort column from the session state + * * @return string */ protected function getSortBy() @@ -981,10 +1000,10 @@ protected function getSortBy() /** * Sets the user sort direction from the session state + * * @param string $sortDirection - * @return void */ - protected function setSortDirection($sortDirection) + protected function setSortDirection($sortDirection): void { if (!in_array($sortDirection, [ MediaLibrary::SORT_DIRECTION_ASC, @@ -998,6 +1017,7 @@ protected function setSortDirection($sortDirection) /** * Gets the user sort direction from the session state + * * @return string */ protected function getSortDirection() @@ -1007,9 +1027,8 @@ protected function getSortDirection() /** * Gets the user selection parameters from the session state - * @return array */ - protected function getSelectionParams() + protected function getSelectionParams(): array { $result = $this->getSession('media_crop_selection_params'); @@ -1038,12 +1057,12 @@ protected function getSelectionParams() /** * Stores the user selection parameters in the session state + * * @param string $selectionMode * @param int $selectionWidth * @param int $selectionHeight - * @return void */ - protected function setSelectionParams($selectionMode, $selectionWidth, $selectionHeight) + protected function setSelectionParams($selectionMode, $selectionWidth, $selectionHeight): void { if (!in_array($selectionMode, [ self::SELECTION_MODE_NORMAL, @@ -1070,30 +1089,24 @@ protected function setSelectionParams($selectionMode, $selectionWidth, $selectio /** * Sets the sidebar visible state - * @param bool $visible - * @return void */ - protected function setSidebarVisible($visible) + protected function setSidebarVisible(bool $visible): void { - $this->putSession('sidebar_visible', !!$visible); + $this->putSession('sidebar_visible', $visible); } /** * Checks if the sidebar is visible - * @return bool */ - protected function getSidebarVisible() + protected function getSidebarVisible(): bool { return $this->getSession('sidebar_visible', true); } /** * Returns an icon for the item type - * @param System\Classes\MediaLibraryItem $item - * @param string $itemType - * @return string */ - protected function itemTypeToIconClass($item, $itemType) + protected function itemTypeToIconClass(?MediaLibraryItem $item, ?string $itemType): string { if ($item->type == MediaLibraryItem::TYPE_FOLDER) { return 'icon-folder'; @@ -1113,10 +1126,10 @@ protected function itemTypeToIconClass($item, $itemType) /** * Splits a path in to segments + * * @param string $path - * @return array */ - protected function splitPathToSegments($path) + protected function splitPathToSegments($path): array { $path = MediaLibrary::validatePath($path, true); $path = explode('/', ltrim($path, '/')); @@ -1136,10 +1149,10 @@ protected function splitPathToSegments($path) /** * Stores a view mode in the session - * @param string $viewMode - * @return void + * + * @throws ApplicationException if $viewMode is not a valid VIEW_MODE_* constant */ - protected function setViewMode($viewMode) + protected function setViewMode(string $viewMode): void { if (!in_array($viewMode, [ self::VIEW_MODE_GRID, @@ -1154,9 +1167,8 @@ protected function setViewMode($viewMode) /** * Returns the current view mode stored in the session - * @return string */ - protected function getViewMode() + protected function getViewMode(): string { return $this->getSession('view_mode', self::VIEW_MODE_GRID); } @@ -1187,91 +1199,6 @@ protected function getThumbnailParams(string $viewMode = null): array ]); } - /** - * Generates a thumbnail image path - * @param array|null $thumbnailParams - * @param string $itemPath - * @param int $lastModified - * @return string - */ - protected function getThumbnailImagePath($thumbnailParams, $itemPath, $lastModified) - { - $itemSignature = md5($itemPath).$lastModified; - - $thumbFile = 'thumb_' . - $itemSignature . '_' . - $thumbnailParams['width'] . 'x' . - $thumbnailParams['height'] . '_' . - $thumbnailParams['mode'] . '.' . - $this->getThumbnailImageExtension($itemPath); - - $partition = implode('/', array_slice(str_split($itemSignature, 3), 0, 3)) . '/'; - - return $this->getThumbnailDirectory().$partition.$thumbFile; - } - - /** - * Preferred thumbnail image extension - * @param string $itemPath - * @return string - */ - protected function getThumbnailImageExtension($itemPath) - { - $extension = pathinfo($itemPath, PATHINFO_EXTENSION); - - if (in_array($extension, ['png', 'gif', 'webp'])) { - return $extension; - } - - return 'jpg'; - } - - /** - * Returns the URL to a thumbnail - */ - protected function getThumbnailImageUrl(string $imagePath): string - { - return Url::to( - rtrim( - Config::get('cms.storage.resized.path', ''), - Config::get('cms.storage.resized.folder', '') - ) . $imagePath - ); - } - - /** - * Get temporary local file path - * @param string $fileName - * @return string - */ - protected function getLocalTempFilePath($fileName) - { - $fileName = md5($fileName.uniqid().microtime()); - - $mediaFolder = Config::get('cms.storage.media.folder', 'media'); - - $path = temp_path() . MediaLibrary::validatePath($mediaFolder, true); - - if (!File::isDirectory($path)) { - File::makeDirectory($path, 0777, true, true); - } - - return $path.'/'.$fileName; - } - - /** - * Get thumbnail directory - * @return string - */ - protected function getThumbnailDirectory() - { - /* - * NOTE: Custom routing for /storage/temp/$thumbnailDirectory must be setup - * to return the thumbnail if not using default 'public' directory - */ - return MediaLibrary::validatePath(Config::get('cms.storage.media.thumbFolder', 'public'), true) . '/'; - } - /** * Get placeholder identifier * @param System\Classes\MediaLibraryItem $item @@ -1298,9 +1225,8 @@ protected function generateThumbnail($thumbnailInfo, $thumbnailParams = null): a return [ 'id' => $id, 'markup' => $this->makePartial('thumbnail-image', [ - 'isError' => false, - 'imageUrl' => Url::to(config('cms.storage.media.path') . $thumbnailInfo['path']) - ]) + 'imageUrl' => MediaLibary::url($thumbnailInfo['path']), + ]), ]; } @@ -1325,17 +1251,18 @@ protected function generateThumbnail($thumbnailInfo, $thumbnailParams = null): a /* * Resize the thumbnail and save to the thumbnails directory */ - $fullThumbnailPath = $this->lazyResizeImage($path, $thumbnailParams); + $thumbnailUrl = $this->getResizedImageUrl($path, $thumbnailParams); /* * Delete the temporary file */ $markup = $this->makePartial('thumbnail-image', [ - 'isError' => false, - 'imageUrl' => $fullThumbnailPath + 'imageUrl' => $thumbnailUrl, ]); } catch (\Throwable $ex) { - $markup = $this->makePartial('thumbnail-image', ['isError' => true]); + $markup = $this->makePartial('thumbnail-image', [ + 'imageUrl' => false, + ]); traceLog($ex->getMessage()); } @@ -1343,7 +1270,7 @@ protected function generateThumbnail($thumbnailInfo, $thumbnailParams = null): a if ($markup && ($id = $thumbnailInfo['id'])) { return [ 'id' => $id, - 'markup' => $markup + 'markup' => $markup, ]; } @@ -1351,9 +1278,9 @@ protected function generateThumbnail($thumbnailInfo, $thumbnailParams = null): a } /** - * Resize an image + * Get the URL to the resized image based on the provided path and parameters */ - protected function lazyResizeImage(string $path, array $params): string + protected function getResizedImageUrl(string $path, array $params): string { return ImageResizer::filterGetUrl( MediaLibrary::url($path), @@ -1366,98 +1293,15 @@ protected function lazyResizeImage(string $path, array $params): string ); } - /** - * Resize an image - */ - protected function resizeImage(string $path, array $params): string - { - return ImageResizer::processImage( - MediaLibrary::url($path), - $params['width'], - $params['height'], - array_merge( - ['mode' => 'exact'], - $params - ), - ImageResizer::METHOD_RESIZE - ); - } - - /** - * Crop an image - */ - protected function cropImage(string $path, array $params): string - { - return ImageResizer::processImage( - MediaLibrary::url($path), - $params['width'], - $params['height'], - array_merge( - ['mode' => 'exact'], - $params - ), - ImageResizer::METHOD_CROP - ); - } - - /** - * Returns the path for the broken image graphic - * @return string - */ - protected function getBrokenImagePath() - { - return __DIR__ . '/mediamanager/assets/images/broken-thumbnail.gif'; - } - - /** - * Returns a CRC32 hash for a broken image - * @return string - */ - protected function getBrokenImageHash() - { - if ($this->brokenImageHash) { - return $this->brokenImageHash; - } - - $fullPath = $this->getBrokenImagePath(); - - return $this->brokenImageHash = hash_file('crc32', $fullPath); - } - // // Cropping // - /** - * Prepares an image for cropping and returns payload containing a URL - * @param string $path - * @param array $params - * @return array - */ - protected function getCropEditImageUrlAndSize($path, $params = null) - { - $url = MediaLibrary::url($path); - - if ($params) { - $url = $this->resizeImage($path, [ - 'mode' => 'exact', - 'width' => $params['width'], - 'height' => $params['height'], - ]); - } - - return [ - 'url' => $url, - 'dimensions' => Str::startsWith($url, '/') - ? getimagesize(base_path($url)) - : getimagesize($url) - ]; - } - /** * Process the provided path and add a suffix of _$int to prevent conflicts * with existing paths - * @TODO: Consider moving this into the File helper and accepting a $disk instance + * + * @todo Consider moving this into the File helper and accepting a $disk instance */ protected function deduplicatePath(string $path, string $suffix = null): string { diff --git a/modules/backend/widgets/mediamanager/assets/images/broken-thumbnail.gif b/modules/backend/widgets/mediamanager/assets/images/broken-thumbnail.gif deleted file mode 100644 index 44519d0684a4c822cc499e104c50407c00e8956f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1097 zcmZ?wbhEHbWM*JyXkcK_whQ?G|G(mY?g-xi1((Eh+i z#(Mch>H3D2mX`VkM*2oZxCj#L>ju z#n95g6{goEKe;qFHLnDwHwB^B5vN{ITF5N`+U$~Alv$RV;#QQOs{r=1RVHq?nBz1L zsy79}YRmZE0?5Y^blRt*Nf6tSB!lEh#Q4EXdEx&B@Nn%t%j5 zO-W8lOo)$*jfswmj0g`44G9hk4Dk2!_3`%d^l*1`b#Zobbg;LxwXwFcv@ka_H8C~< zW+**f9c?X54RtkD6=fww1$jAH8EGj=32`w|5n&-g0e(JS9&Rp94t6$H7G@?!1_s5S VEDRu^10q1h1_KkbOHVk1H2~ujf8ziE diff --git a/modules/backend/widgets/mediamanager/assets/js/mediamanager-browser-min.js b/modules/backend/widgets/mediamanager/assets/js/mediamanager-browser-min.js index a8eedb6e9c..3088fafe52 100644 --- a/modules/backend/widgets/mediamanager/assets/js/mediamanager-browser-min.js +++ b/modules/backend/widgets/mediamanager/assets/js/mediamanager-browser-min.js @@ -499,8 +499,7 @@ MediaManagerImageCropPopup.prototype.updateSelectionSizeLabel=function(width,hei return}this.selectionSizeLabel.setAttribute('class','') this.selectionSizeLabel.querySelector('[data-label=selection-width]').textContent=parseInt(width) this.selectionSizeLabel.querySelector('[data-label=selection-height]').textContent=parseInt(height)} -MediaManagerImageCropPopup.prototype.onPopupHidden=function(event,element,popup){this.$popupElement.find('form').request(this.options.alias+'::onEndCroppingSession') -$(document).trigger('mousedown') +MediaManagerImageCropPopup.prototype.onPopupHidden=function(event,element,popup){$(document).trigger('mousedown') this.dispose()} MediaManagerImageCropPopup.prototype.onPopupShown=function(event,element,popup){this.$popupElement=popup this.$popupElement.on('change','[data-control="selection-mode"]',this.proxy(this.onSelectionModeChanged)) diff --git a/modules/backend/widgets/mediamanager/assets/js/mediamanager.imagecroppopup.js b/modules/backend/widgets/mediamanager/assets/js/mediamanager.imagecroppopup.js index b740c12f30..bae831840a 100644 --- a/modules/backend/widgets/mediamanager/assets/js/mediamanager.imagecroppopup.js +++ b/modules/backend/widgets/mediamanager/assets/js/mediamanager.imagecroppopup.js @@ -378,8 +378,6 @@ // ============================ MediaManagerImageCropPopup.prototype.onPopupHidden = function(event, element, popup) { - this.$popupElement.find('form').request(this.options.alias+'::onEndCroppingSession') - // Release clickedElement reference inside redactor.js // If we don't do it, the image editor popup DOM elements // won't be removed from the memory. diff --git a/modules/backend/widgets/mediamanager/partials/_item-icon.php b/modules/backend/widgets/mediamanager/partials/_item-icon.php index c974362ab5..a8c8596579 100644 --- a/modules/backend/widgets/mediamanager/partials/_item-icon.php +++ b/modules/backend/widgets/mediamanager/partials/_item-icon.php @@ -2,22 +2,23 @@
lazyResizeImage($item->path, $thumbnailParams) + && $thumbnailUrl = $this->getResizedImageUrl($item->path, $thumbnailParams) ): ?>
- -
+
makePartial('thumbnail-image', [ - 'imageUrl' => $thumbnailPath + 'imageUrl' => $thumbnailUrl, ]) ?>
diff --git a/modules/system/classes/ImageResizer.php b/modules/system/classes/ImageResizer.php index 4112fe1bc4..692f81e2fc 100644 --- a/modules/system/classes/ImageResizer.php +++ b/modules/system/classes/ImageResizer.php @@ -48,12 +48,6 @@ class ImageResizer */ public const CACHE_PREFIX = 'system.resizer.'; - /** - * Available methods to use when processing images - */ - public const METHOD_RESIZE = 'resize'; - public const METHOD_CROP = 'crop'; - /** * @var array Available sources to get images from */ @@ -108,27 +102,6 @@ public function __construct($image, $width = 0, $height = 0, $options = []) $this->options = array_merge($this->getDefaultOptions(), $options); } - /** - * A simple static method for resizing an image and receiving the output path - * - * @throws ApplicationException If an invalid resize mode is passed to the the method. - */ - public static function processImage( - mixed $image, - int|float $width = 0, - int|float $height = 0, - array $options = [], - string $method = self::METHOD_RESIZE - ): string { - if (!in_array($method, [static::METHOD_RESIZE, static::METHOD_CROP])) { - throw new \ApplicationException('Invalid method passed to processImage'); - } - - $resizer = new static($image, $width, $height, $options); - $resizer->{$method}(); - return $resizer->getPathToResizedImage(); - } - /** * Get the default options for the resizer */ From b29d1b988348e071790970ddce31c1678a9c2ef0 Mon Sep 17 00:00:00 2001 From: Luke Towers Date: Wed, 6 Jul 2022 15:00:34 -0600 Subject: [PATCH 3/3] Code style fixes --- modules/backend/widgets/MediaManager.php | 1 - phpcs.xml | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/backend/widgets/MediaManager.php b/modules/backend/widgets/MediaManager.php index 74d40688fe..b2c4d1eeb2 100644 --- a/modules/backend/widgets/MediaManager.php +++ b/modules/backend/widgets/MediaManager.php @@ -293,7 +293,6 @@ public function onDeleteItem(): array * Add to bulk collection */ $filesToDelete[] = $path; - } elseif ($type === MediaLibraryItem::TYPE_FOLDER) { /* * Delete single folder diff --git a/phpcs.xml b/phpcs.xml index 89efeb88ba..bdac268c45 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -131,6 +131,8 @@ */vendor/* modules/system/views/exception.php + + modules/backend/widgets/mediamanager/partials/_item-icon.php tests/fixtures/plugins/testvendor/goto/Plugin.php