@@ -87,6 +87,12 @@ class Resize
87
87
* @var StoreManagerInterface $storeManager
88
88
*/
89
89
protected $ storeManager ;
90
+ /**
91
+ * Absolute original path if png to jpg is use
92
+ *
93
+ * @var string $absolutePathoriginal
94
+ */
95
+ protected $ absolutePathoriginal ;
90
96
/**
91
97
* @var array
92
98
*
@@ -234,6 +240,13 @@ public function resizeAndGetUrl(string $imagePath, $width, $height, array $resiz
234
240
$ this ->logger ->error ("Web200_ImageResize: could not find image: \n" . $ e ->getMessage ());
235
241
}
236
242
try {
243
+ if ($ this ->config ->convertPngImage ()) {
244
+ $ this ->absolutePathoriginal = $ this ->getAbsolutePathOriginal ();
245
+ if (preg_match ('/\.png$/ ' , $ this ->absolutePathoriginal )) {
246
+ $ this ->relativeFilename = preg_replace ('/(\.png$)/ ' , '.jpg ' , $ this ->relativeFilename );
247
+ }
248
+ }
249
+
237
250
// Check if resized image already exists in cache
238
251
$ resizedUrl = $ this ->getResizedImageUrl ();
239
252
if (!$ resizedUrl && $ this ->resizeAndSaveImage ()) {
@@ -406,11 +419,9 @@ protected function getImageUrl(): string
406
419
*/
407
420
protected function convertPngToJpg (): void
408
421
{
409
- $ absolutePath = $ this ->getAbsolutePathOriginal ();
410
- if (preg_match ('/\.png$/ ' , $ absolutePath )) {
411
- $ newAbsolutePath = preg_replace ('/(\.png$)/ ' , '.jpg ' , $ absolutePath );
412
- $ this ->relativeFilename = preg_replace ('/(\.png$)/ ' , '.jpg ' , $ this ->relativeFilename );
413
- $ imageInput = imagecreatefrompng ($ absolutePath );
422
+ if (preg_match ('/\.png$/ ' , $ this ->absolutePathoriginal )) {
423
+ $ newAbsolutePath = preg_replace ('/(\.png$)/ ' , '.jpg ' , $ this ->absolutePathoriginal );
424
+ $ imageInput = imagecreatefrompng ($ this ->absolutePathoriginal );
414
425
$ width = imagesx ($ imageInput );
415
426
$ height = imagesy ($ imageInput );
416
427
$ imageOutput = imagecreatetruecolor ($ width , $ height );
@@ -430,12 +441,15 @@ protected function convertPngToJpg(): void
430
441
*/
431
442
protected function resizeAndSaveImage (): bool
432
443
{
433
- if (!$ this ->mediaDirectoryRead ->isFile ($ this ->relativeFilename )) {
434
- return false ;
435
- }
436
-
437
- if ($ this ->config ->convertPngImage ()){
444
+ if ($ this ->config ->convertPngImage ()) {
445
+ if (!$ this ->mediaDirectoryRead ->isFile ($ this ->absolutePathoriginal )) {
446
+ return false ;
447
+ }
438
448
$ this ->convertPngToJpg ();
449
+ } else {
450
+ if (!$ this ->mediaDirectoryRead ->isFile ($ this ->relativeFilename )) {
451
+ return false ;
452
+ }
439
453
}
440
454
441
455
$ imageAdapter = $ this ->imageAdapterFactory ->create ();
0 commit comments