blob: b6bd2004a1c2004d6c75967d16694fce9af53d0d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
<?php
/**
* ownCloud - gallery
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Olivier Paroz <owncloud@interfasys.ch>
*
* @copyright Olivier Paroz 2014-2015
*/
namespace OCA\Gallery\Http;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Http;
/**
* A renderer for images
*
* @package OCA\Gallery\Http
*/
class ImageResponse extends Response {
/**
* @var \OC_Image|string
*/
private $preview;
/**
* Constructor
*
* @param array $image image meta data
* @param int $statusCode the HTTP status code, defaults to 200
*/
public function __construct(array $image, $statusCode = Http::STATUS_OK) {
$name = $image['name'];
$this->preview = $image['preview'];
$this->setStatus($statusCode);
$this->addHeader('Content-type', $image['mimetype'] . '; charset=utf-8');
$this->addHeader('Content-Disposition',
'attachment; filename*=UTF-8\'\'' . rawurlencode($name) . '; filename="'
. rawurlencode($name) . '"'
);
}
/**
* Returns the rendered image
*
* @return string the file
*/
public function render() {
if ($this->preview instanceof \OC_Image) {
// Uses imagepng() to output the image
return $this->preview->data();
} else {
return $this->preview;
}
}
}
|