Select Git revision
COPYING-AGPL
image.php 27.37 KiB
<?php
/**
* ownCloud
*
* @author Thomas Tanghus
* @copyright 2011 Thomas Tanghus <thomas@tanghus.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
/**
* Class for basic image manipulation
*/
class OC_Image {
protected $resource = false; // tmp resource.
protected $imagetype = IMAGETYPE_PNG; // Default to png if file type isn't evident.
protected $bit_depth = 24;
protected $filepath = null;
/**
* @brief Get mime type for an image file.
* @param $filepath The path to a local image file.
* @returns string The mime type if the it could be determined, otherwise an empty string.
*/
static public function getMimeTypeForFile($filepath) {
$imagetype = exif_imagetype($filepath);
return $imagetype ? image_type_to_mime_type($imagetype) : '';
}
/**
* @brief Constructor.
* @param $imageref The path to a local file, a base64 encoded string or a resource created by an imagecreate* function.
* @returns bool False on error
*/
public function __construct($imageref = null) {
//OC_Log::write('core',__METHOD__.'(): start', OC_Log::DEBUG);
if(!extension_loaded('gd') || !function_exists('gd_info')) {
OC_Log::write('core', __METHOD__.'(): GD module not installed', OC_Log::ERROR);
return false;
}
if(!is_null($imageref)) {
$this->load($imageref);
}
}
/**
* @brief Determine whether the object contains an image resource.
* @returns bool
*/
public function valid() { // apparently you can't name a method 'empty'...
return is_resource($this->resource);
}
/**
* @brief Returns the MIME type of the image or an empty string if no image is loaded.
* @returns int
*/
public function mimeType() {