I want to create images using Base64EncodedData in Magento 2.
Asked
Active
Viewed 959 times
1 Answers
3
Magento 2 provides some APIs to work with images:
vendor/magento/framework/Api/ImageContent.php
vendor/magento/framework/Api/Data/ImageContentInterface.php
vendor/magento/framework/Api/ImageContentValidator.php
vendor/magento/framework/Api/ImageProcessor.php
Let's go to this file: dev/tests/api-functional/testsuite/Magento/Customer/Api/AccountManagementCustomAttributesTest.php, we can find some testing cases:
$testImagePath = __DIR__ . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'test_image.jpg';
$imageData = base64_encode(file_get_contents($testImagePath));
$image = $this->imageFactory->create()
->setType('image/jpeg')
->setName('sample.jpeg')
->setBase64EncodedData($imageData);
We can try to test with the playground file.
Khoa TruongDinh
- 32,054
- 11
- 88
- 155
$this->imageFactory? – Lucas D.A.W. Jan 20 '20 at 14:06