ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
MakeGreyScale.php
Go to the documentation of this file.
1 <?php
18 declare(strict_types=1);
19 
21 
28 
34 {
36 
37  public const ID = 'greyscale';
38 
39  public function getId(): string
40  {
41  return self::ID;
42  }
43 
44  public function canHandleDefinition(FlavourDefinition $definition): bool
45  {
46  return $definition instanceof ToGreyScale;
47  }
48 
49  public function dependsOnEngine(): ?string
50  {
51  return GDEngine::class;
52  }
53 
54  public function processStream(
55  FileInformation $information,
56  FileStream $stream,
57  FlavourDefinition $for_definition
58  ): \Generator {
60  $image = $this->from($stream);
61  if (!is_resource($image) && !$image instanceof \GdImage) {
62  return;
63  }
64  imagefilter($image, IMG_FILTER_GRAYSCALE, 50, true);
65 
66  yield new Result(
67  $for_definition,
68  $this->to($image, $for_definition->getQuality()),
69  0,
70  $for_definition->persist()
71  );
72  }
73 }
canHandleDefinition(FlavourDefinition $definition)
Check if a corresponding configuration can be processed by this Machine.
dependsOnEngine()
Return the class name of the Engine that is required for this Machine to work.
persist()
Define whether the generated flavor and the respective streams should be persisted, or whether they should only be generated and used in-memory.
processStream(FileInformation $information, FileStream $stream, FlavourDefinition $for_definition)
to(\GdImage $image, int $quality=null)
Currently this is the only way to make a FileStream from a GD image resource.
The base interface for all filesystem streams.
Definition: FileStream.php:31