magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.36k stars 9.28k forks source link

imagecreatetruecolor(): Argument #2 ($height) must be greater than 0. Can't upload specific image #37988

Open yuriichayka opened 9 months ago

yuriichayka commented 9 months ago

Preconditions and environment

Steps to reproduce

  1. Enable new media gallery, see the instruction by [Link](https://experienceleague.adobe.com/docs/commerce-admin/content-design/media/gallery/media-gallery.html?lang=
  2. When creating a new CMS block, try to upload the attached image through Page Builder/Media/Image element test_image

Expected result

The image is uploaded and works fine

Actual result

The following error occurs in exception.log, and image isn't uploaded:

report.CRITICAL: ValueError: imagecreatetruecolor(): Argument #2 ($height) must be greater than 0 in vendor/magento/framework/Image/Adapter/Gd2.php:422
Stack trace:
vendor/magento/framework/Image/Adapter/Gd2.php(422): imagecreatetruecolor()
vendor/magento/module-cms/Model/Wysiwyg/Images/Storage.php(717): Magento\Framework\Image\Adapter\Gd2->resize()
vendor/magento/module-media-gallery-ui/Plugin/CreateThumbnails.php(51): Magento\Cms\Model\Wysiwyg\Images\Storage->resizeFile()
vendor/magento/framework/Interception/Interceptor.php(121): Magento\MediaGalleryUi\Plugin\CreateThumbnails->beforeExecute()
vendor/magento/framework/Interception/Interceptor.php(153): Magento\MediaGallerySynchronizationApi\Model\ImportFilesComposite\Interceptor->Magento\Framework\Interception\{closure}()

Additional information

This also prevents the following command to be executed - php bin/magento media-gallery:sync Hotfix for us was the following patch:

diff --git vendor/magento/module-cms/Model/Wysiwyg/Images/Storage.php vendor/magento/module-cms/Model/Wysiwyg/Images/Storage.php
--- vendor/magento/module-cms/Model/Wysiwyg/Images/Storage.php
+++ vendor/magento/module-cms/Model/Wysiwyg/Images/Storage.php  (date 1662984202000)
@@ -713,7 +713,15 @@

         [$imageWidth, $imageHeight] = $this->getResizedParams($source);

-        $image->resize($imageWidth, $imageHeight);
+        try {
+            $image->resize($imageWidth, $imageHeight);
+        } catch (\Throwable $e) {
+            $this->logger->critical(
+                'FAILED WYSIWYG IMAGE RESIZING: ' . ' error: ' . $e->getMessage() . '. path: ' . $realPath
+            );
+
+            return false;
+        }
         $dest = $targetDir . '/' . $this->ioFile->getPathInfo($source)['basename'];
         $image->save($dest);
         if ($this->_directory->isFile($this->_directory->getRelativePath($dest))) {

Release note

No response

Triage and priority

m2-assistant[bot] commented 9 months ago

Hi @yuriichayka. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

m2-assistant[bot] commented 9 months ago

Hi @engcom-Bravo. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

engcom-Bravo commented 9 months ago

Hi @yuriichayka,

Thank you for reporting and collaboration.

Verified the issue on Magento 2.4-develop instance and the issue is reproducible.Kindly refer the attached video.

Steps to reproduce

267701397-ae403625-deae-4971-850f-a7c6b617d698

https://github.com/magento/magento2/assets/51680745/7dd49f6d-7b47-4b49-b219-869dd2abd6c9

As per document it will supports JPG,GIF,PNG images here we are uploading PNG image it is not at all uploading.

Hence Confirming the issue.

Thanks.

github-jira-sync-bot commented 9 months ago

:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-9554 is successfully created for this GitHub issue.

m2-assistant[bot] commented 9 months ago

:white_check_mark: Confirmed by @engcom-Bravo. Thank you for verifying the issue.
Issue Available: @engcom-Bravo, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.