ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
MakeGreyScale.php
Go to the documentation of this file.
1 <?php
18 declare(strict_types=1);
19 
21 
29 
35 {
37 
38  public const ID = 'greyscale';
39 
40  public function getId(): string
41  {
42  return self::ID;
43  }
44 
45  public function canHandleDefinition(FlavourDefinition $definition): bool
46  {
47  return $definition instanceof ToGreyScale;
48  }
49 
50  public function dependsOnEngine(): ?string
51  {
52  return GDEngine::class;
53  }
54 
55  public function processStream(
56  FileInformation $information,
57  FileStream $stream,
58  FlavourDefinition $for_definition
59  ): \Generator {
61  $image = $this->from($stream);
62  if (!is_resource($image) && !$image instanceof \GdImage) {
63  return;
64  }
65  imagefilter($image, IMG_FILTER_GRAYSCALE, 50, true);
66 
67  yield new Result(
68  $for_definition,
69  $this->to($image, $for_definition->getQuality()),
70  0,
71  $for_definition->persist()
72  );
73  }
74 }
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