Create an Image from an instance of Imagick.

@param \Imagick $imagick Instance of Imagick.

@return Image
544832
public static function createFromCore( $imagick ) {
        return new self( $imagick, '', $imagick->getImageWidth(), $imagick->getImageHeight(), $imagick->getImageFormat() );
    }
655403
private function cloneResource($img) {
        $w = imagesx($img);
        $h = imagesy($img);

        // Get the transparent color from a 256 palette image.
        $trans = imagecolortransparent($img);

        if (imageistruecolor($img)) { // If this is a true color image...
            $clone = imagecreatetruecolor($w, $h);
            imagealphablending($clone, false);
            imagesavealpha($clone, true);
        } else { // If this is a 256 color palette image...
            $clone = imagecreate($w, $h);

            // If the image has transparency...
            if ($trans >= 0) {
                $rgb = imagecolorsforindex($img, $trans);

                imagesavealpha($clone, true);
                $trans_index = imagecolorallocatealpha($clone, $rgb['red'], $rgb['green'], $rgb['blue'], $rgb['alpha']);
                imagefill($clone, 0, 0, $trans_index);
            }
        }

        // Create the Clone!!
        imagecopy($clone, $img, 0, 0, 0, 0, $w, $h);

        return $clone;
    }
1145698
public function createImageFromUrl($url)
    {
        $file = wei()->file->downloadOnDemand($url);
        $file = file_get_contents($file);

        return imagecreatefromstring($file);
    }
206549
public function flatten(&$image){
        if($image->isAnimated()){
            $imagick = $image->getCore()->mergeImageLayers(\Imagick::LAYERMETHOD_FLATTEN);
            $image = new Image(
                $imagick,
                $image->getImageFile(),
                $image->getWidth(),
                $image->getHeight(),
                $image->getType(),
                '', // blocks
                false // animated
            );
        }
        return $this;
    }
326193
protected function saveImage($filePath, Imagick $image, $compression_quality)
    {
        $image->setImageCompression(Imagick::COMPRESSION_JPEG);
        $image->setImageCompressionQuality($compression_quality);
        $image->stripImage();
        $image->writeImage($filePath);

        return $image;
    }
83130
protected function createImagineInstance()
    {
        $driver = ConfigQuery::read("imagine_graphic_driver", "gd");

        switch ($driver) {
            case 'imagick':
                $image = new ImagickImagine();
                break;

            case 'gmagick':
                $image = new GmagickImagine();
                break;

            case 'gd':
            default:
                $image = new Imagine();
        }

        return $image;
    }
72335
protected function getHighestEnergyPoint(\Imagick $image)
    {
        $size = $image->getImageGeometry();
        // It's more performant doing random pixel uplook via GD
        $im = imagecreatefromstring($image->getImageBlob());
        if ($im === false) {
            $msg = 'GD failed to create image from string';
            throw new \Exception($msg);
        }
        $xcenter = 0;
        $ycenter = 0;
        $sum = 0;
        // Only sample 1/50 of all the pixels in the image
        $sampleSize = round($size['height']*$size['width'])/50;

        for ($k=0; $k<$sampleSize; $k++) {
            $i = mt_rand(0, $size['width']-1);
            $j = mt_rand(0, $size['height']-1);

            $rgb = imagecolorat($im, $i, $j);
            $r = ($rgb >> 16) & 0xFF;
            $g = ($rgb >> 8) & 0xFF;
            $b = $rgb & 0xFF;

            $val = $this->rgb2bw($r, $g, $b);
            $sum += $val;
            $xcenter += ($i+1)*$val;
            $ycenter += ($j+1)*$val;
        }

        if ($sum) {
            $xcenter /= $sum;
            $ycenter /= $sum;
        }

        $point = array('x' => $xcenter, 'y' => $ycenter, 'sum' => $sum/round($size['height']*$size['width']));

        return $point;
    }
563028
private function createIm() {
        $w1 = imagesx($this->image1);
        $w2 = imagesx($this->image2);
        $h1 = imagesy($this->image1);
        $h2 = imagesy($this->image2);

        if ($this->position === self::POSITION_LEFT || $this->position === self::POSITION_RIGHT) {
            $w = $w1 + $w2 + $this->space;
            $h = max($h1, $h2);
        } else {
            $w = max($w1, $w2);
            $h = $h1 + $h2 + $this->space;
        }

        $this->im = imagecreatetruecolor($w, $h);
        imagefill($this->im, 0, 0, $this->background->allocate($this->im));

        // We start defining position of images
        if ($this->position === self::POSITION_TOP) {
            if ($w1 > $w2) {
                $posX1 = 0;
                $posX2 = $this->findPosition($w1, $w2, $this->alignment);
            } else {
                $a = $this->changeAlignment($this->alignment);
                $posX1 = $this->findPosition($w1, $w2, $a);
                $posX2 = 0;
            }

            $posY2 = 0;
            $posY1 = $h2 + $this->space;
        } elseif ($this->position === self::POSITION_LEFT) {
            if ($w1 > $w2) {
                $posY1 = 0;
                $posY2 = $this->findPosition($h1, $h2, $this->alignment);
            } else {
                $a = $this->changeAlignment($this->alignment);
                $posY2 = 0;
                $posY1 = $this->findPosition($h1, $h2, $a);
            }

            $posX2 = 0;
            $posX1 = $w2 + $this->space;
        } elseif ($this->position === self::POSITION_BOTTOM) {
            if ($w1 > $w2) {
                $posX2 = $this->findPosition($w1, $w2, $this->alignment);
                $posX1 = 0;
            } else {
                $a = $this->changeAlignment($this->alignment);
                $posX2 = 0;
                $posX1 = $this->findPosition($w1, $w2, $a);
            }

            $posY1 = 0;
            $posY2 = $h1 + $this->space;
        } else { // defaults to RIGHT
            if ($w1 > $w2) {
                $posY2 = $this->findPosition($h1, $h2, $this->alignment);
                $posY1 = 0;
            } else {
                $a = $this->changeAlignment($this->alignment);
                $posY2 = 0;
                $posY1 = $this->findPosition($h1, $h2, $a);
            }

            $posX1 = 0;
            $posX2 = $w1 + $this->space;
        }

        imagecopy($this->im, $this->image1, $posX1, $posY1, 0, 0, $w1, $h1);
        imagecopy($this->im, $this->image2, $posX2, $posY2, 0, 0, $w2, $h2);
    }
684283
public function make()
    {
        $ext = strtolower(strrchr($this->path, '.'));
        $path = storage_path('app/public/') . $this->path;
        switch ($ext) {
            case '.jpg':
            case '.jpeg':
                $this->image = @imagecreatefromjpeg($path);
                break;
            case '.gif':
                $this->image = @imagecreatefromgif($path);
                break;
            case '.png':
                $this->image = @imagecreatefrompng($path);
                break;
            default:
                $this->image = false;
                break;
        }

        if (false === $this->image) {
            throw new ImageNotFoundException('Image extension not supported!');
        }
        $this->width = imagesx($this->image);
        $this->height = imagesy($this->image);

        return $this;
    }
911054
public function addImage($src, $alt="", $before=true) {
		$img=new HtmlImg("image-" . $this->identifier, $src, $alt);
		$img->setClass("");
		$this->addContent($img, $before);
		return $img;
	}
627483
public function createFrom($image)
    {
        $type           = pathinfo($image, PATHINFO_EXTENSION);
        $type           = ($type === 'jpg') ? 'jpeg' : $type;
        $createFrom     = 'ImageCreateFrom' . $type;

        return $createFrom($image);
    }
814619
function imageObjectInternal( $createMissing = true )
    {
        if ( $this->ImageObject === null or
             $this->ImageObjectRef === null )
        {
            if ( $createMissing )
                $this->create( $this->Width, $this->Height );
        }
        return $this->ImageObject;
    }
647854
protected function _autorotate(\Imagick $image)
    {
        switch ($image->getImageOrientation()) {
            case \Imagick::ORIENTATION_TOPRIGHT:
                $image->flopImage();
                break;
            case \Imagick::ORIENTATION_BOTTOMRIGHT:
                $image->rotateImage('#000', 180);
                break;
            case \Imagick::ORIENTATION_BOTTOMLEFT:
                $image->flopImage();
                $image->rotateImage('#000', 180);
                break;
            case \Imagick::ORIENTATION_LEFTTOP:
                $image->flopImage();
                $image->rotateImage('#000', -90);
                break;
            case \Imagick::ORIENTATION_RIGHTTOP:
                $image->rotateImage('#000', 90);
                break;
            case \Imagick::ORIENTATION_RIGHTBOTTOM:
                $image->flopImage();
                $image->rotateImage('#000', 90);
                break;
            case \Imagick::ORIENTATION_LEFTBOTTOM:
                $image->rotateImage('#000', -90);
                break;
        }
        $image->setImageOrientation(\Imagick::ORIENTATION_TOPLEFT);
    }
663598
public function createImage($src, $alt = null)
    {
        return $this->image = new Card\Image($src, $alt);
    }
1148408
private function initImage($image)
    {
        if(is_string($image))
        {
            return new Imagick($image);
        }
        elseif ($image instanceof Imagick)
        {
            return $image;
        }
        else
        {
            throw new Exception('Image input must be Imagick object or string path ('.gettype($image).' sent)');
        }
    }
1034957
private function setPixel($r, $g, $b, $a = null)
    {
        $a = $a ?? 1;

        return $this->pixel = new \ImagickPixel(
            sprintf('rgba(%d, %d, %d, %.2F)', $r, $g, $b, $a)
        );
    }
873643
public static function convertImagickToGDRessource(\Imagick $imagick, $png = false)
  {
    $imagick->setImageFormat('png');
    $data = $imagick->getimageblob();
    $im = imagecreatefromstring($data);

    if ($png) {
      imagealphablending($im, true); // setting alpha blending on
      imagesavealpha($im, true);
    }

    return $im;
  }