22
33namespace SMS \FluidComponents \Domain \Model ;
44
5- use SMS \FluidComponents \Exception \InvalidFilePathException ;
6- use TYPO3 \CMS \Core \Utility \GeneralUtility ;
75use TYPO3 \CMS \Core \Utility \PathUtility ;
6+ use TYPO3 \CMS \Core \Utility \GeneralUtility ;
7+ use SMS \FluidComponents \Interfaces \ImageWithDimensions ;
8+ use SMS \FluidComponents \Exception \InvalidFilePathException ;
9+ use SMS \FluidComponents \Interfaces \ProcessableImage ;
10+ use TYPO3 \CMS \Core \Imaging \GraphicalFunctions ;
11+ use TYPO3 \CMS \Core \Imaging \ImageManipulation \Area ;
812
913/**
1014 * Data structure for a local image resource to be passed to a component.
1115 *
1216 * @deprecated, use FalImage instead
1317 */
14- class LocalImage extends Image
18+ class LocalImage extends Image implements ImageWithDimensions, ProcessableImage
1519{
1620 /**
1721 * Type of image to differentiate implementations in Fluid templates.
@@ -23,6 +27,16 @@ class LocalImage extends Image
2327 */
2428 protected string $ filePath = '' ;
2529
30+ /**
31+ * Image width, will be determined at first access
32+ */
33+ protected int $ width = 0 ;
34+
35+ /**
36+ * Image height, will be determined at first access
37+ */
38+ protected int $ height = 0 ;
39+
2640 /**
2741 * Creates an image object for a local image resource.
2842 *
@@ -59,4 +73,41 @@ public function getPublicUrl(): string
5973 {
6074 return PathUtility::getAbsoluteWebPath ($ this ->filePath );
6175 }
76+
77+ public function getHeight (): int
78+ {
79+ if (!isset ($ this ->height )) {
80+ $ this ->getImageDimensions ();
81+ }
82+ return $ this ->height ;
83+ }
84+
85+ public function getWidth (): int
86+ {
87+ if (!isset ($ this ->height )) {
88+ $ this ->getImageDimensions ();
89+ }
90+ return $ this ->width ;
91+ }
92+
93+ protected function getImageDimensions (): void
94+ {
95+ $ graphicalFunctions = GeneralUtility::makeInstance (GraphicalFunctions::class);
96+ $ imageDimensions = $ graphicalFunctions ->getImageDimensions ($ this ->getFilePath ());
97+ $ this ->width = (int ) $ imageDimensions [0 ];
98+ $ this ->height = (int ) $ imageDimensions [1 ];
99+ }
100+
101+ public function process (int $ width , int $ height , ?string $ format , Area $ cropArea ): ProcessableImage
102+ {
103+ $ imageService = GeneralUtility::makeInstance (ImageService::class);
104+ $ file = $ imageService ->getImage ($ this ->getFilePath (), null , false );
105+ $ processedImage = $ imageService ->applyProcessingInstructions ($ file , [
106+ 'width ' => $ width ,
107+ 'height ' => $ height ,
108+ 'fileExtension ' => $ format ,
109+ 'crop ' => ($ cropArea ->isEmpty ()) ? null : $ cropArea ->makeAbsoluteBasedOnFile ($ file )
110+ ]);
111+ return new FalImage ($ processedImage );
112+ }
62113}
0 commit comments