Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
11 / 11
ImageResponse
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
11 / 11
 __construct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
8 / 8
 render
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
3 / 3
<?php
/**
 * Gallery
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later. See the COPYING file.
 *
 * @author Olivier Paroz <galleryapps@oparoz.com>
 *
 * @copyright Olivier Paroz 2014-2016
 */
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;
        }
    }
}