public static function castImageType(Image\Type $type, array $a, Stub $stub, $isNested, $filter = 0) { unset($a["Bolt\\Filesystem\\Handler\\Image\\Typename"]); $a[Caster::PREFIX_VIRTUAL . 'string'] = $type->toString(); $a[Caster::PREFIX_VIRTUAL . 'mimeType'] = $type->getMimeType(); $a[Caster::PREFIX_VIRTUAL . 'extension'] = $type->getExtension(); $stub->class .= sprintf(' "%s"', $type->toString()); return $a; }
public function testConstruct() { $exif = new Image\Exif([]); $type = Image\Type::getById(IMAGETYPE_JPEG); $info = new Image\Info(new Image\Dimensions(1024, 768), $type, 2, 7, 'Marcel Marceau', $exif); $this->assertInstanceOf(Image\Info::class, $info); }
/** * Get an image. * * @param string $filename * * @return \Bolt\Filesystem\Handler\Image */ public function imageInfo($filename) { $image = $this->app['filesystem']->getImage('files://' . $filename); if (!$image->exists()) { return new Info(new Dimensions(0, 0), Type::getById(IMAGETYPE_UNKNOWN), 0, 0, null, new Exif([])); } return $image->getInfo(); }
/** * Writes the image to a file. * * @param string $file */ public function toFile($file) { switch ($this->type->getId()) { case IMAGETYPE_BMP: imagewbmp($this->resource, $file); break; case IMAGETYPE_GIF: imagegif($this->resource, $file); break; case IMAGETYPE_JPEG: imageinterlace($this->resource, 1); imagejpeg($this->resource, $file, static::$quality); break; case IMAGETYPE_PNG: $compression = static::convertJpegQualityToPngCompression(static::$quality); imagepng($this->resource, $file, $compression); break; default: throw new \RuntimeException('Unknown image type'); } }
protected function getTypeFromMetadata($metadata) { $ext = pathinfo($metadata['path'], PATHINFO_EXTENSION); if (in_array($ext, Handler\Image\Type::getExtensions())) { return 'image'; } elseif ($ext === 'json') { return 'json'; } elseif ($ext === 'yaml' || $ext === 'yml') { return 'yaml'; } elseif (in_array($ext, $this->getDocumentExtensions())) { return 'document'; } return $metadata['type']; }
public function testGetExtensions() { $extensions = Type::getExtensions(); $this->assertContains('jpeg', $extensions); $this->assertContains('jpg', $extensions); }
/** * {@inheritdoc} */ public function unserialize($serialized) { $data = unserialize($serialized); $this->dimensions = new Dimensions($data['dims'][0], $data['dims'][1]); $this->type = Type::getById($data['type']); $this->bits = $data['bits']; $this->channels = $data['channels']; $this->mime = $data['mime']; $this->exif = new Exif($data['exif']); }
private function getTypeFromPath($path) { $ext = pathinfo($path, PATHINFO_EXTENSION); if (in_array($ext, Handler\Image\Type::getExtensions())) { return 'image'; } elseif ($ext === 'json') { return 'json'; } elseif ($ext === 'yaml' || $ext === 'yml') { return 'yaml'; } elseif (in_array($ext, $this->getDocumentExtensions())) { return 'document'; } return null; }
/** * @param array $info * @param Exif $exif * * @return Info */ protected static function createFromArray(array $info, Exif $exif) { // Add defaults to skip isset checks $info += [0 => 0, 1 => 0, 2 => 0, 'bits' => 0, 'channels' => 0, 'mime' => '']; return new static(new Dimensions($info[0], $info[1]), Type::getById($info[2]), $info['bits'], $info['channels'], $info['mime'], $exif); }