/** * @return mixed */ public function getMimeType() { if (!$this->_mimeType) { $this->_mimeType = IOHelper::getMimeType($this->getRealPath()); } return $this->_mimeType; }
/** * Constructor * * @param null $imagePath * @param null $imageUrl */ public function __construct($imagePath = null, $imageUrl = null) { if ($imagePath != 'null') { $this['path'] = $imagePath; $imageInfo = @getimagesize($imagePath); $this['width'] = $imageInfo[0]; $this['height'] = $imageInfo[1]; $this['extension'] = IOHelper::getExtension($imagePath); $this['mimeType'] = IOHelper::getMimeType($imagePath); $this['size'] = IOHelper::getFileSize($imagePath); } if ($imageUrl != 'null') { $this['url'] = $imageUrl; } }
/** * Get cropped image url. * * @param null|array $settings * * @return string */ public function getUrl($settings = null) { // Get image $file = $this->getFile(); // Do the cropping $this->applyCrop($file, $settings); // Get base64 of crop $base64 = $this->getBase64($file); // Get mime $mime = IOHelper::getMimeType($file); // Delete the temp image IOHelper::deleteFile($file); // Return base64 string return 'data:' . $mime . ';base64,' . $base64; }
/** * Constructor * * @param null $imagePath * @param null $imageUrl */ public function __construct($imagePath = null, $imageUrl = null, $paths = null, $transform = null) { if ($imagePath != 'null') { $this['path'] = $imagePath; $this['extension'] = IOHelper::getExtension($imagePath); $this['mimeType'] = IOHelper::getMimeType($imagePath); $this['size'] = IOHelper::getFileSize($imagePath); $imageInfo = @getimagesize($imagePath); if (is_array($imageInfo) && $imageInfo[0] !== '' && $imageInfo[1] !== '') { $this['width'] = $imageInfo[0]; $this['height'] = $imageInfo[1]; } else { // Couldn't get size. Calculate size based on source image and transform. $sourceImageInfo = @getimagesize($paths->sourcePath . $paths->sourceFilename); $sourceSize = new \Imagine\Image\Box($sourceImageInfo[0], $sourceImageInfo[1]); $targetCrop = craft()->imager->getCropSize($sourceSize, $transform); $this['width'] = $targetCrop->getWidth(); $this['height'] = $targetCrop->getHeight(); } } if ($imageUrl != 'null') { $this['url'] = $imageUrl; } }
/** * @return string */ public function getMimeType() { return IOHelper::getMimeType($this->filename); }
/** * Validates that temp file is actually an image file * * @param string $remoteImagePath url of remote image * @param string $tempLocalImage file pointer to temp image * * @return boolean */ private function _validateImage($remoteImagePath, $tempLocalImage) { // Check to make sure the asset is an image if (IOHelper::getFileKind(IOHelper::getExtension($tempLocalImage)) === 'image' && substr(IOHelper::getMimeType($tempLocalImage), 0, 5) === 'image') { return true; } return false; }
/** * Upload a file to Rackspace. * * @param $targetUri * @param $sourceFile * * @return bool */ private function _uploadFile($targetUri, $sourceFile) { $fileSize = IOHelper::getFileSize($sourceFile); $fp = fopen($sourceFile, "r"); $headers = array('Content-type: ' . IOHelper::getMimeType($sourceFile), 'Content-length: ' . $fileSize); $curlOptions = array(CURLOPT_UPLOAD => true, CURLOPT_INFILE => $fp, CURLOPT_INFILESIZE => $fileSize); $targetUri = $this->_prepareRequestURI($this->getSettings()->container, $targetUri); $this->_doAuthenticatedRequest(static::RACKSPACE_STORAGE_OPERATION, $targetUri, 'PUT', $headers, $curlOptions); fclose($fp); return true; }