public open ( $imageFile ) : GifByteStream | ||
$imageFile | ||
Результат | GifByteStream |
public function open($imageFile)
{
$fp = fopen($imageFile, 'rb');
// Binary read
if ($fp === false) {
throw new \Exception(sprintf('Error loading file: "%s".', $imageFile));
}
$size = filesize($imageFile);
$bytes = fread($fp, $size);
$bytes = unpack('H*', $bytes);
// Unpack as hex
$bytes = $bytes[1];
fclose($fp);
return new GifByteStream($bytes);
}
/** * Load a GIF image. * * @param string $imageFile * * @return Image * @throws \Exception */ private static function _createGif($imageFile) { $gift = new GifHelper(); $bytes = $gift->open($imageFile); $animated = $gift->isAnimated($bytes); $blocks = ''; if ($animated) { $blocks = $gift->decode($bytes); } $gd = @imagecreatefromgif($imageFile); if (!$gd) { throw new \Exception(sprintf('Could not open "%s". Not a valid %s file.', $imageFile, ImageType::GIF)); } return new self($gd, $imageFile, imagesx($gd), imagesy($gd), ImageType::GIF, $blocks, $animated); }