Skip to content

Instantly share code, notes, and snippets.

@romainbessugesmeusy
Last active December 19, 2019 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romainbessugesmeusy/eeda0b09764ececb4c7eee49db1c2d36 to your computer and use it in GitHub Desktop.
Save romainbessugesmeusy/eeda0b09764ececb4c7eee49db1c2d36 to your computer and use it in GitHub Desktop.
<?php
namespace AppBundle\DataObject;
use Pimcore\Model\DataObject\PrintingColor;
use Pimcore\Model\Element\AdminStyle;
class PrintingColorAdminStyle extends AdminStyle
{
public function __construct($element)
{
parent::__construct($element);
if (!($element instanceof PrintingColor)) {
return;
}
/** @var $element PrintingColor */
$rgb = $element->getRbgPreview();
$filename = "printing_color_{$rgb->getHex(false, false)}.png";
if (!file_exists(PIMCORE_ASSET_DIRECTORY . "/printing_colors")) {
mkdir(PIMCORE_ASSET_DIRECTORY . "/printing_colors");
}
$path = PIMCORE_ASSET_DIRECTORY . "/printing_colors/$filename";
if (!file_exists($path)) {
$im = imagecreatetruecolor(20, 20);
$bg = imagecolorallocate($im, $rgb->getR(), $rgb->getG(), $rgb->getB());
imagefilledrectangle($im, 0, 0, 20, 20, $bg);
imagepng($im, $path);
imagedestroy($im);
}
$this->elementIcon = "/printing_colors/$filename";
$this->elementIconClass = null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment