xref: /webtrees/app/Contracts/ImageFactoryInterface.php (revision 78606cf427772fbdc5222ff607ee23f43078f94b)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2022 webtrees development team
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18declare(strict_types=1);
19
20namespace Fisharebest\Webtrees\Contracts;
21
22use Fisharebest\Webtrees\MediaFile;
23use Intervention\Image\Image;
24use League\Flysystem\FilesystemOperator;
25use Psr\Http\Message\ResponseInterface;
26
27/**
28 * Make an image (from another image).
29 */
30interface ImageFactoryInterface
31{
32    /**
33     * Send the original file - either inline or as a download.
34     *
35     * @param FilesystemOperator $filesystem
36     * @param string             $path
37     * @param bool               $download
38     *
39     * @return ResponseInterface
40     */
41    public function fileResponse(FilesystemOperator $filesystem, string $path, bool $download): ResponseInterface;
42
43    /**
44     * Send the original file - either inline or as a download.
45     *
46     * @param FilesystemOperator $filesystem
47     * @param string             $path
48     * @param int                $width
49     * @param int                $height
50     * @param string             $fit
51     *
52     * @return ResponseInterface
53     */
54    public function thumbnailResponse(
55        FilesystemOperator $filesystem,
56        string $path,
57        int $width,
58        int $height,
59        string $fit
60    ): ResponseInterface;
61
62    /**
63     * Create a full-size version of an image.
64     *
65     * @param MediaFile $media_file
66     * @param bool      $add_watermark
67     * @param bool      $download
68     *
69     * @return ResponseInterface
70     */
71    public function mediaFileResponse(MediaFile $media_file, bool $add_watermark, bool $download): ResponseInterface;
72
73    /**
74     * Create a smaller version of an image.
75     *
76     * @param MediaFile $media_file
77     * @param int       $width
78     * @param int       $height
79     * @param string    $fit
80     * @param bool      $add_watermark
81     *
82     * @return ResponseInterface
83     */
84    public function mediaFileThumbnailResponse(
85        MediaFile $media_file,
86        int $width,
87        int $height,
88        string $fit,
89        bool $add_watermark
90    ): ResponseInterface;
91
92    /**
93     * Does a full-sized image need a watermark?
94     *
95     * @param MediaFile     $media_file
96     * @param UserInterface $user
97     *
98     * @return bool
99     */
100    public function fileNeedsWatermark(MediaFile $media_file, UserInterface $user): bool;
101
102    /**
103     * Does a thumbnail image need a watermark?
104     *
105     * @param MediaFile     $media_file
106     * @param UserInterface $user
107     *
108     * @return bool
109     */
110    public function thumbnailNeedsWatermark(MediaFile $media_file, UserInterface $user): bool;
111
112    /**
113     * Create a watermark image, perhaps specific to a media-file.
114     *
115     * @param int       $width
116     * @param int       $height
117     * @param MediaFile $media_file
118     *
119     * @return Image
120     */
121    public function createWatermark(int $width, int $height, MediaFile $media_file): Image;
122
123    /**
124     * Add a watermark to an image.
125     *
126     * @param Image $image
127     * @param Image $watermark
128     *
129     * @return Image
130     */
131    public function addWatermark(Image $image, Image $watermark): Image;
132
133    /**
134     * Send a replacement image, to replace one that could not be found or created.
135     *
136     * @param string $text HTTP status code or file extension
137     *
138     * @return ResponseInterface
139     */
140    public function replacementImageResponse(string $text): ResponseInterface;
141}
142