本文整理汇总了PHP中sfImage::getMIMEType方法的典型用法代码示例。如果您正苦于以下问题:PHP sfImage::getMIMEType方法的具体用法?PHP sfImage::getMIMEType怎么用?PHP sfImage::getMIMEType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sfImage
的用法示例。
在下文中一共展示了sfImage::getMIMEType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createMask
protected function createMask(sfImage $image, $w, $h)
{
// Create a mask png image of the area you want in the circle/ellipse (a 'magicpink' image with a black shape on it, with black set to the colour of alpha transparency) - $mask
$mask = $image->getAdapter()->getTransparentImage($w, $h);
// Set the masking colours
if (false === $this->getColor() || 'image/png' == $image->getMIMEType()) {
$mask_black = imagecolorallocate($mask, 0, 0, 0);
} else {
$mask_black = $image->getAdapter()->getColorByHex($mask, $this->getColor());
}
// Cannot use white as transparent mask if color is set to white
if ($this->getColor() === '#FFFFFF' || $this->getColor() === false) {
$mask_transparent = imagecolorallocate($mask, 255, 0, 0);
} else {
$mask_color = imagecolorsforindex($mask, imagecolorat($image->getAdapter()->getHolder(), 0, 0));
$mask_transparent = imagecolorallocate($mask, $mask_color['red'], $mask_color['green'], $mask_color['blue']);
}
imagecolortransparent($mask, $mask_transparent);
imagefill($mask, 0, 0, $mask_black);
// Draw the rounded rectangle for the mask
$this->imagefillroundedrect($mask, 0, 0, $w, $h, $this->getRadius(), $mask_transparent);
$mask_image = clone $image;
$mask_image->getAdapter()->setHolder($mask);
return $mask_image;
}
示例2: transform
protected function transform(sfImage $image)
{
switch ($image->getMIMEType()) {
case 'image/png':
$this->transformAlpha($image);
break;
case 'image/gif':
case 'image/jpg':
default:
$this->transformDefault($image);
}
return $image;
}
示例3: importFavicon
/**
* saves the favicon of a communitiy
*
* @author Matthias Pfefferle
*
* @param Object $pCommunity
* @return boolean true|false
*/
public static function importFavicon($pCommunity, $pPath = self::PATH_TYPE_URL)
{
try {
// try to get an image from websnapr
$lImage = UrlUtils::getUrlContent($pCommunity->getFavicon());
$lBasePath = DIRECTORY_SEPARATOR . 'favicons' . DIRECTORY_SEPARATOR . $pCommunity->getSlug() . '.png';
// create folder structure and save the image to our local filesystem
$path = sfConfig::get('sf_upload_dir') . $lBasePath;
$fp = fopen($path, 'w+');
fputs($fp, $lImage);
fclose($fp);
// get mime-type
$lImgData = GetImageSize($path);
if ($lImgData['mime'] != "image/png") {
$lImg = new sfImage($path, $lImgData['mime'], 'GD');
$lImg->getMIMEType();
$lImg->setQuality(100);
$lImg->saveAs($path, 'image/png');
}
unset($lImage);
if ($pPath == self::PATH_TYPE_URL) {
return DIRECTORY_SEPARATOR . sfConfig::get('sf_upload_dir_name') . $lBasePath;
} else {
return $path;
}
} catch (Exception $e) {
sfContext::getInstance()->getLogger()->err("{ImageImporter} Exception: " . print_r($e, true));
return null;
}
}
示例4: transform
/**
* Apply the transform to the sfImage object.
*
* @param sfImage
* @return sfImage
*/
protected function transform(sfImage $image)
{
$resource = $image->getAdapter()->getHolder();
$x = imagesx($resource);
$y = imagesy($resource);
// If the width or height is not valid then enforce the aspect ratio
if (!is_numeric($this->width) || $this->width < 1) {
$this->width = round($x / $y * $this->height);
} else {
if (!is_numeric($this->height) || $this->height < 1) {
$this->height = round($y / $x * $this->width);
}
}
$dest_resource = $image->getAdapter()->getTransparentImage($this->width, $this->height);
// Preserving transparency for alpha PNGs
if ($image->getMIMEType() == 'image/png') {
imagealphablending($dest_resource, false);
imagesavealpha($dest_resource, true);
}
// Finally do our resizing
imagecopyresampled($dest_resource, $resource, 0, 0, 0, 0, $this->width, $this->height, $x, $y);
imagedestroy($resource);
$image->getAdapter()->setHolder($dest_resource);
return $image;
}