Skip to content

Commit 0f266ba

Browse files
committed
Added module.
0 parents  commit 0f266ba

File tree

6 files changed

+88
-0
lines changed

6 files changed

+88
-0
lines changed

Framework/Image.php

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
namespace OnePica\NoImage\Framework;
3+
4+
use Magento\Framework\Image as ImageFramework;
5+
6+
/**
7+
* Class for creating placeholder which will prevent throwing an error
8+
*
9+
* @package OnePica\NoImage\Framework
10+
*/
11+
class Image extends ImageFramework
12+
{
13+
/**
14+
* Initiate placeholder for non-exist images
15+
*
16+
* {@inheritdoc}
17+
*/
18+
public function open()
19+
{
20+
if ($this->_fileName && !file_exists($this->_fileName)) {
21+
$this->initPlaceholder();
22+
}
23+
parent::open();
24+
}
25+
26+
/**
27+
* Init placeholder
28+
*
29+
* @return $this
30+
*/
31+
public function initPlaceholder()
32+
{
33+
// Create a 20*20 image
34+
$im = imagecreate(20, 20);
35+
36+
// White background and blue text
37+
imagecolorallocate($im, 255, 255, 255);
38+
// Write the string at the top left
39+
imagestring($im, 6, 6, 2, 'X', imagecolorallocate($im, 0, 0, 255));
40+
41+
//init directory
42+
if (!is_dir(dirname($this->_fileName))) {
43+
mkdir(dirname($this->_fileName), 0775, true);
44+
}
45+
46+
imagepng($im, $this->_fileName);
47+
imagedestroy($im);
48+
49+
return $this;
50+
}
51+
}

README.md

Whitespace-only changes.

composer.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "onepica/mage2-dev-no-image",
3+
"license": "GPL-2.0",
4+
"description": "Fix for Magento 2. It fixes the case when there is no a required option swatch image in media.",
5+
"require": {
6+
"php": "~7.0.6",
7+
"magento/framework": "^100.1"
8+
},
9+
"type": "magento2-module",
10+
"version": "1.0.0",
11+
"autoload": {
12+
"files": [
13+
"registration.php"
14+
],
15+
"psr-4": {
16+
"OnePica\\NoImage\\": ""
17+
}
18+
}
19+
}

etc/di.xml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0"?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
3+
<preference for="Magento\Framework\Image" type="OnePica\NoImage\Framework\Image" />
4+
</config>

etc/module.xml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0"?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
3+
<module name="MageDev_NoImage" setup_version="1.0.0">
4+
<sequence>
5+
<module name="Magento_Framework"/>
6+
</sequence>
7+
</module>
8+
</config>

registration.php

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
\Magento\Framework\Component\ComponentRegistrar::register(
3+
\Magento\Framework\Component\ComponentRegistrar::MODULE,
4+
'OnePica_NoImage',
5+
__DIR__
6+
);

0 commit comments

Comments
 (0)