@param string $binaryImage
@param string $filename

@return string URL to the image
346381
public function upload($binaryImage, $filename)
    {
        $targetFile = $this->getTargetPath($filename);
        $this->ensureDirectoryExists(dirname($targetFile));
        $this->filesystem->dumpFile($targetFile, $binaryImage);

        return $targetFile;
    }
1372470
static public function createFromFile($filename) {
		if (!file_exists($filename))
			throw new Exception('Invalid (filename) parameter! File does not exist!');

		$image_info = getimagesize($filename);
		if ($image_info === false)
			throw new Exception('Invalid (filename) parameter! File is corrupted!');

		switch ($image_info[2]) {
			case IMAGETYPE_JPEG:
			case IMAGETYPE_JPEG2000:
				$image = imagecreatefromjpeg($filename);
				break;
			case IMAGETYPE_PNG:
				$image = imagecreatefrompng($filename);
				break;
			case IMAGETYPE_GIF:
				$image = imagecreatefromgif($filename);
				break;
			case IMAGETYPE_WBMP:
				$image = imagecreatefromwbmp($filename);
				break;
			case IMAGETYPE_BMP:
				$image = imagecreatefrombmp($filename);
				break;
			default:
				throw new Exception('Unknown image format!');
				break;
		}

		return new self($image);
	}
1064409
public function getImageByName($filename)
    {
        $images = $this->getImages();
        foreach ($images as $image) {
            if ($image->file == $filename) {
                return $image;
            }
        }

        return null;
    }
44018
public static function generateThumbnail($fileName, $data = [])
    {
        FileHelper::createDirectory( \Yii::getAlias('@thumbnail') . '/' . date('Y/m/d'));
        $thumbnail_save =  \Yii::getAlias('@thumbnail') . '/' . $fileName;
        $size_width = get_setting_value('media_configuration', 'thumbnail_size_width', 150);
        $size_height = get_setting_value('media_configuration', 'thumbnail_size_height', 150);
        Image::getImagine()
            ->open(self::getFileNameSave($fileName))
            ->thumbnail(new Box($size_width, $size_height))
            ->save($thumbnail_save , ['quality' => self::getQualitySetting(50, $data)]);

        FileHelper::createDirectory(\Yii::getAlias('@medium') . '/' . date('Y/m/d'));
        $thumbnail_save = \Yii::getAlias('@medium') . '/' . $fileName;
        $size_width = get_setting_value('media_configuration', 'medium_size_width', 150);
        $size_height = get_setting_value('media_configuration', 'medium_size_height', 150);
        Image::getImagine()
            ->open(self::getFileNameSave($fileName))
            ->thumbnail(new Box($size_width, $size_height))
            ->save($thumbnail_save , ['quality' => self::getQualitySetting(50, $data)]);

        FileHelper::createDirectory(\Yii::getAlias('@large') . '/' . date('Y/m/d'));
        $thumbnail_save = \Yii::getAlias('@large') . '/' . $fileName;
        $size_width = get_setting_value('media_configuration', 'large_size_width', 150);
        $size_height = get_setting_value('media_configuration', 'large_size_height', 150);
        Image::getImagine()
            ->open(self::getFileNameSave($fileName))
            ->thumbnail(new Box($size_width, $size_height))
            ->save($thumbnail_save , ['quality' => self::getQualitySetting(50, $data)]);
    }
132844
protected function getDownloadUrl(BinaryFileResponse $response): string
    {
        return url('/nova-vendor/maatwebsite/laravel-nova-excel/download?') . http_build_query([
                'path'     => $response->getFile()->getPathname(),
                'filename' => $this->getFilename(),
            ]);
    }
253980
public function updateFileResource(File $resource, $binaryData)
    {
        $url = self::makeUrl(null, $resource->uri);

        $body = $binaryData;
        $response = $this->service->sendBinary($url, array(201, 200), $body, MimeMapper::mapType($resource->type), 'attachment; filename=' . $resource->label, $resource->description, 'PUT');
        return File::createFromJSON(json_decode($response, true), get_class($resource));

    }
668140
public static function fromBinary(&$binaryData, &$offsetIndex = 0)
    {
        $parsedObject = new static();
        self::parseIdentifier($binaryData[$offsetIndex], $parsedObject->getType(), $offsetIndex++);
        $contentLength = self::parseContentLength($binaryData, $offsetIndex);
        $startIndex = $offsetIndex;

        $children = [];
        $octetsToRead = $contentLength;
        while ($octetsToRead > 0) {
            $newChild = ASNObject::fromBinary($binaryData, $offsetIndex);
            $octetsToRead -= $newChild->getObjectLength();
            $children[] = $newChild;
        }

        if ($octetsToRead !== 0) {
            throw new ParserException("Sequence length incorrect", $startIndex);
        }

        $parsedObject->addChildren($children);
        $parsedObject->setContentLength($contentLength);

        return $parsedObject;
    }
508486
protected function file($file, string $fileName = null, string $disposition = ResponseHeaderBag::DISPOSITION_ATTACHMENT): BinaryFileResponse
    {
        $response = new BinaryFileResponse($file);
        $response->setContentDisposition($disposition, null === $fileName ? $response->getFile()->getFilename() : $fileName);

        return $response;
    }
285966
private Image buildWebImage(final WebImage jrImage) {

        final String url = jrImage.getUrl();

        Image image = null;
        if (url == null || url.isEmpty()) {
            LOGGER.error("Image : {} not found !", url);
        } else {
            image = new Image(url);
        }
        return image;
    }
197575
private function ImageCreateFromBMP($filename)
		# Author:     DHKold
		# Date:     The 15th of June 2005
		# Version:    2.0B
		# Purpose:    To create an image from a BMP file.
		# Param in:   BMP file to open.
		# Param out:  Return a resource like the other ImageCreateFrom functions
		# Reference:  http://us3.php.net/manual/en/function.imagecreate.php#53879
		# Bug fix:    Author:   domelca at terra dot es
		#       Date:   06 March 2008
		#       Fix:    Correct 16bit BMP support
		# Notes:
		#
	{

		//Ouverture du fichier en mode binaire
		if ( ! $f1 = fopen($filename, "rb"))
		{
			return false;
		}

		//1 : Chargement des ent�tes FICHIER
		$FILE = unpack("vfile_type/Vfile_size/Vreserved/Vbitmap_offset", fread($f1, 14));
		if ($FILE['file_type'] != 19778)
		{
			return false;
		}

		//2 : Chargement des ent�tes BMP
		$BMP = unpack('Vheader_size/Vwidth/Vheight/vplanes/vbits_per_pixel' .
			'/Vcompression/Vsize_bitmap/Vhoriz_resolution' .
			'/Vvert_resolution/Vcolors_used/Vcolors_important', fread($f1, 40));
		$BMP['colors'] = pow(2, $BMP['bits_per_pixel']);

		if ($BMP['size_bitmap'] == 0)
		{
			$BMP['size_bitmap'] = $FILE['file_size'] - $FILE['bitmap_offset'];
		}

		$BMP['bytes_per_pixel'] = $BMP['bits_per_pixel'] / 8;
		$BMP['bytes_per_pixel2'] = ceil($BMP['bytes_per_pixel']);
		$BMP['decal'] = ($BMP['width'] * $BMP['bytes_per_pixel'] / 4);
		$BMP['decal'] -= floor($BMP['width'] * $BMP['bytes_per_pixel'] / 4);
		$BMP['decal'] = 4 - (4 * $BMP['decal']);

		if ($BMP['decal'] == 4)
		{
			$BMP['decal'] = 0;
		}

		//3 : Chargement des couleurs de la palette
		$PALETTE = array();
		if ($BMP['colors'] < 16777216)
		{
			$PALETTE = unpack('V' . $BMP['colors'], fread($f1, $BMP['colors'] * 4));
		}

		//4 : Cr�ation de l'image
		$IMG = fread($f1, $BMP['size_bitmap']);
		$VIDE = chr(0);

		$res = imagecreatetruecolor($BMP['width'], $BMP['height']);
		$P = 0;
		$Y = $BMP['height'] - 1;
		while ($Y >= 0)
		{
			$X = 0;
			while ($X < $BMP['width'])
			{
				if ($BMP['bits_per_pixel'] == 24)
				{
					$COLOR = unpack("V", substr($IMG, $P, 3) . $VIDE);
				}
				elseif ($BMP['bits_per_pixel'] == 16)
				{

					/*
           * BMP 16bit fix
           * =================
           *
           * Ref: http://us3.php.net/manual/en/function.imagecreate.php#81604
           *
           * Notes:
           * "don't work with bmp 16 bits_per_pixel. change pixel
           * generator for this."
           *
           */

					// *** Original code (don't work)
					//$COLOR = unpack("n",substr($IMG,$P,2));
					//$COLOR[1] = $PALETTE[$COLOR[1]+1];

					$COLOR = unpack("v", substr($IMG, $P, 2));
					$blue = ($COLOR[1] & 0x001f) << 3;
					$green = ($COLOR[1] & 0x07e0) >> 3;
					$red = ($COLOR[1] & 0xf800) >> 8;
					$COLOR[1] = $red * 65536 + $green * 256 + $blue;

				}
				elseif ($BMP['bits_per_pixel'] == 8)
				{
					$COLOR = unpack("n", $VIDE . substr($IMG, $P, 1));
					$COLOR[1] = $PALETTE[ $COLOR[1] + 1 ];
				}
				elseif ($BMP['bits_per_pixel'] == 4)
				{
					$COLOR = unpack("n", $VIDE . substr($IMG, floor($P), 1));
					if (($P * 2) % 2 == 0)
					{
						$COLOR[1] = ($COLOR[1] >> 4);
					}
					else
					{
						$COLOR[1] = ($COLOR[1] & 0x0F);
					}
					$COLOR[1] = $PALETTE[ $COLOR[1] + 1 ];
				}
				elseif ($BMP['bits_per_pixel'] == 1)
				{
					$COLOR = unpack("n", $VIDE . substr($IMG, floor($P), 1));
					if (($P * 8) % 8 == 0)
					{
						$COLOR[1] = $COLOR[1] >> 7;
					}
					elseif (($P * 8) % 8 == 1)
					{
						$COLOR[1] = ($COLOR[1] & 0x40) >> 6;
					}
					elseif (($P * 8) % 8 == 2)
					{
						$COLOR[1] = ($COLOR[1] & 0x20) >> 5;
					}
					elseif (($P * 8) % 8 == 3)
					{
						$COLOR[1] = ($COLOR[1] & 0x10) >> 4;
					}
					elseif (($P * 8) % 8 == 4)
					{
						$COLOR[1] = ($COLOR[1] & 0x8) >> 3;
					}
					elseif (($P * 8) % 8 == 5)
					{
						$COLOR[1] = ($COLOR[1] & 0x4) >> 2;
					}
					elseif (($P * 8) % 8 == 6)
					{
						$COLOR[1] = ($COLOR[1] & 0x2) >> 1;
					}
					elseif (($P * 8) % 8 == 7)
					{
						$COLOR[1] = ($COLOR[1] & 0x1);
					}
					$COLOR[1] = $PALETTE[ $COLOR[1] + 1 ];
				}
				else
				{
					return false;
				}

				imagesetpixel($res, $X, $Y, $COLOR[1]);
				$X++;
				$P += $BMP['bytes_per_pixel'];
			}

			$Y--;
			$P += $BMP['decal'];
		}
		//Fermeture du fichier
		fclose($f1);

		return $res;
	}
628722
public function getBinarySlice($binary, $start, $size, $binaryLength)
    {
        $binary >>= $binaryLength - ($start + $size);
        $mask = ((1 << $size) - 1);

        return $binary & $mask;
    }
1208069
static public function open($filename) {
		if (!file_exists($filename))
			throw new Exception('Invalid (filename) parameter! File does not exist!');

		$image_info = getimagesize($filename);
		if ($image_info === false)
			throw new Exception('Invalid (filename) parameter! File is corrupted!');

		switch ($image_info[2]) {
			case IMAGETYPE_JPEG:
			case IMAGETYPE_JPEG2000:
				$image = imagecreatefromjpeg($filename);
				break;
			case IMAGETYPE_PNG:
				$image = imagecreatefrompng($filename);
				break;
			case IMAGETYPE_GIF:
				$image = imagecreatefromgif($filename);
				break;
			case IMAGETYPE_WBMP:
				$image = imagecreatefromwbmp($filename);
				break;
			case IMAGETYPE_BMP:
				$image = imagecreatefrombmp($filename);
				break;
			case IMAGETYPE_XBM:
				$image = imagecreatefromxbm($filename);
				break;
			case IMAGETYPE_XPM:
				$image = imagecreatefromxpm($filename);
				break;
			case IMAGETYPE_WEBP:
				$image = imagecreatefromwebp($filename);
				break;
			default:
				throw new Exception('Unknown image format!');
				break;
		}
		imagealphablending($image, false);
		imagesavealpha($image, true);

		return new self($image);
	}
119718
public static Attachment fromBinaryBytes( byte[] bytes, MediaType mediaType ) {
        if( !mediaType.isBinary() ) {
            throw new IllegalArgumentException( "MediaType must be binary" );
        }
        return new Attachment(BaseEncoding.base64().encode( bytes ), mediaType, null );
    }
1239357
public static function newFromFile(
        string $filename,
        array $options = []
    ): Image {
        Utils::debugLog('newFromFile', [
            'instance' => null,
            'arguments' => [$filename, $options]
        ]);

        $options = self::unwrap($options);
        $result = vips_image_new_from_file($filename, $options);
        self::errorIsArray($result);
        $result = self::wrapResult($result);

        Utils::debugLog('newFromFile', ['result' => $result]);

        return $result;
    }
259576
public static function convertBinaryStringToNumber(string $binaryString): int
    {
        return self::convertEndianness((ord($binaryString{1}) << 8) + (ord($binaryString{0}) & 255));
    }
1061853
public function imageTag($filename, $attributes)
    {
        $absolutePath = $this->file($filename);
        $webPath = $this->parser->absolutePathToWebPath($absolutePath);

        $config = $this->getConfig();
        $composer = $config['image_tag'];

        return $composer->process(array($webPath), array($absolutePath), $attributes);
    }
599146
public function setBinaryContent($binaryContent, $mimeType = null)
    {
        if (empty($binaryContent)) {
            throw new ImageException('Empty image', ImageException::EMPTY_IMAGE);
        }
        $this->binaryContent = $binaryContent;
        $this->mimeType = $mimeType;
        $this->binaryContentDirty = false;
        $this->imagineImage = null;
        // we reset one shot dump options
        $this->ephemeralImagineOptions = [];
    }