Skip to content

[6.x] Images#18482

Open
riasvdv wants to merge 3 commits intofeature/port-image-transformsfrom
feature/port-images
Open

[6.x] Images#18482
riasvdv wants to merge 3 commits intofeature/port-image-transformsfrom
feature/port-images

Conversation

@riasvdv
Copy link
Contributor

@riasvdv riasvdv commented Feb 26, 2026

No description provided.

@riasvdv riasvdv changed the title Feature/port images [6.x] Images Feb 26, 2026
@riasvdv riasvdv requested a review from Copilot February 26, 2026 12:30
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates image-related functionality out of the Yii2 adapter layer into the main CraftCms\Cms\Image namespace, adds an Images service + facade, and updates core/legacy callers and tests to use the new APIs.

Changes:

  • Introduces new image domain classes (Images, ImageHelper, Svg, enums) and an Images facade.
  • Refactors legacy Yii2 image service/helpers to act as deprecated proxies/aliases to the new implementations.
  • Moves/rewrites image tests and fixtures into the main test suite (Feature/Unit), removing Yii2-adapter unit tests.

Reviewed changes

Copilot reviewed 41 out of 59 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
yii2-adapter/tests/unit/services/images/ImagesTest.php Removed Yii2-adapter unit tests for the legacy images service.
yii2-adapter/tests/unit/services/images/.gitignore Removed sandbox ignore (legacy test sandbox no longer used).
yii2-adapter/tests/unit/services/ImageTransformsTest.php Removed Yii2-adapter unit tests for legacy transform helper behavior.
yii2-adapter/tests/unit/helpers/ImageHelperTest.php Removed Yii2-adapter unit tests for legacy image helper functions.
yii2-adapter/tests/_data/assets/files/png-that-is-svg.png Removed legacy fixture file.
yii2-adapter/tests/_data/assets/files/no-svg.svg Removed legacy fixture file.
yii2-adapter/legacy/web/assets/cp/CpAsset.php Uses new Images facade for isImagick Craft CP bootstrap data.
yii2-adapter/legacy/services/Images.php Converts legacy service into a deprecated proxy to the new CraftCms\Cms\Image\Images service.
yii2-adapter/legacy/image/SvgAllowedAttributes.php Replaces legacy implementation with alias/deprecation bridge to new SvgAllowedAttributes.
yii2-adapter/legacy/image/Svg.php Replaces legacy SVG class with alias/deprecation bridge to new Svg.
yii2-adapter/legacy/helpers/ImageTransforms.php Deprecated helper now delegates to CraftCms\Cms\Image\ImageTransformHelper (includes phpdoc tweaks).
yii2-adapter/legacy/helpers/Image.php Deprecated helper now delegates to CraftCms\Cms\Image\ImageHelper and maps EXIF constants to enum values.
yii2-adapter/legacy/helpers/Assets.php Updates image editor source generation to use the new Images facade.
yii2-adapter/legacy/base/Image.php Replaces legacy base image class with alias/deprecation bridge to new CraftCms\Cms\Image\Image.
yii2-adapter/legacy/base/ApplicationTrait.php Marks getImages() as deprecated in favor of the new images service.
tests/_data/assets/files/random.tiff Adds TIFF fixture for ImageHelper/image-size/exif capability tests.
tests/_data/assets/files/random.tif Adds .tif fixture (used for negative EXIF capability cases).
tests/_data/assets/files/no-dimension-svg.svg Adds SVG fixture without width/height attributes (viewBox-only).
tests/_data/assets/files/invalid-ihdr.png Adds malformed PNG fixture to exercise PNG parsing error paths.
tests/_data/assets/files/ign.jpg Adds JPEG fixture used by PNG metadata tests (negative case).
tests/_data/assets/files/gng.svg Adds SVG fixture used by SVG size parsing tests.
tests/_data/assets/files/dirty-svg.svg Adds SVG fixture with unsafe tags to verify sanitization behavior.
tests/Unit/Image/ImageTransformHelperTest.php Adds provider-based coverage to ensure extendTransform() matches legacy cases.
tests/Feature/Image/SvgTest.php Adds feature tests for SVG load/resize/crop/save behavior.
tests/Feature/Image/RasterTest.php Adds feature tests for raster load/resize/crop and SVG rasterization (Imagick-gated).
tests/Feature/Image/ImagesTest.php Adds feature tests for the new Images service (sanitization, EXIF, GIF config, memory checks).
tests/Feature/Image/ImageHelperTest.php Adds feature tests for ImageHelper (dimensions, web-safe, PNG metadata, streams, EXIF cleanup).
src/Utility/Utilities/SystemReport.php Uses app(Images::class) instead of Craft::$app->getImages() when reporting image driver.
src/User/Users.php Switches user photo validation from legacy craft\helpers\Image to new CraftCms\Cms\Image\ImageHelper.
src/Twig/Variables/Image.php Updates Twig variable dependency to new CraftCms\Cms\Image\ImageHelper.
src/Support/Html.php Switches SVG sanitizer allowed-attributes reference to the new CraftCms\Cms\Image\SvgAllowedAttributes.
src/Support/Facades/Images.php Introduces Laravel facade for CraftCms\Cms\Image\Images.
src/Image/SvgAllowedAttributes.php Adds allowed-attributes implementation for SVG sanitization.
src/Image/Svg.php Adds new core SVG image implementation.
src/Image/Images.php Adds new singleton images service (driver detection, load/clean, EXIF rotation/stripping, format support).
src/Image/ImageTransformer.php Updates to use new ImageHelper/Images service for image editing and transform eligibility checks.
src/Image/ImageTransformHelper.php Updates to use new ImageHelper/Images service and updates type docs for returned image object.
src/Image/ImageHelper.php Adds new core image helper (dimensions, web-safe, PNG header parsing, stream size parsing, EXIF cleanup).
src/Image/Image.php Adds new abstract image base class used by raster/SVG implementations.
src/Image/Enums/ImageDriver.php Adds enum for configured image drivers.
src/Image/Enums/ExifOrientation.php Adds enum mapping EXIF orientation values.
src/Http/Controllers/Users/SaveUserController.php Switches uploaded photo validation from legacy helper to ImageHelper.
src/Dashboard/Widgets/CraftSupport.php Injects Images service and uses it to report image driver/version.
src/Cp/Rebrand.php Switches to new CraftCms\Cms\Image\ImageHelper import.
src/Asset/Elements/Asset.php Updates all image-manipulation checks and sizing helpers to use new ImageHelper.
src/Asset/Assets.php Updates thumb/preview logic to use new ImageHelper for manipulatable/web-safe checks.
src/Asset/AssetIndexer.php Updates dimension detection to use new ImageHelper (file and stream-based).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

[$width, $height] = ImageHelper::parseSvgSize($svg);

// If the size is defined by viewbox only, add in width and height attributes
if (! preg_match(self::SVG_WIDTH_RE, $svg) && preg_match(self::SVG_HEIGHT_RE, $svg)) {
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Svg::loadImage(), the condition for injecting width/height attributes doesn’t match the comment (“size is defined by viewbox only”). As written it only runs when width is missing and height is present; viewBox-only SVGs have neither width nor height. Consider changing the condition to check that both width and height are missing (or otherwise align the comment and logic).

Suggested change
if (! preg_match(self::SVG_WIDTH_RE, $svg) && preg_match(self::SVG_HEIGHT_RE, $svg)) {
if (! preg_match(self::SVG_WIDTH_RE, $svg) && ! preg_match(self::SVG_HEIGHT_RE, $svg)) {

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@riasvdv riasvdv requested a review from brandonkelly February 26, 2026 12:54
@riasvdv riasvdv marked this pull request as ready for review February 26, 2026 12:54
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

Successfully merging this pull request may close these issues.

2 participants