本文整理汇总了PHP中image_type_to_mime_type函数的典型用法代码示例。如果您正苦于以下问题:PHP image_type_to_mime_type函数的具体用法?PHP image_type_to_mime_type怎么用?PHP image_type_to_mime_type使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了image_type_to_mime_type函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: upload
/**
* Upload an image.
*
* @param $file
* @return array
*/
public function upload(array $file)
{
if (!$file) {
$status = ['status' => 'error', 'message' => GENERIC_UPLOAD_ERROR_MESSAGE];
return $status;
}
$tempName = $file['tmp_name'];
if (is_null($tempName)) {
$status = ['status' => 'error', 'message' => GENERIC_UPLOAD_ERROR_MESSAGE];
return $status;
}
$imageInfo = getimagesize($tempName);
if (!$imageInfo) {
$status = ['status' => 'error', 'message' => 'Only images are allowed'];
return $status;
}
$fileType = image_type_to_mime_type(exif_imagetype($tempName));
if (!in_array($fileType, $this->_allowedTypes)) {
$status = ['status' => 'error', 'message' => 'File type not allowed'];
return $status;
}
$fileName = htmlentities($file['name']);
$height = $this->_imagick->getImageHeight();
$width = $this->_imagick->getImageWidth();
$uploadPath = $_SERVER['DOCUMENT_ROOT'] . PROPERTY_IMG_TMP_DIR;
if (!move_uploaded_file($tempName, $uploadPath . "/{$fileName}")) {
$status = ['status' => 'error', 'message' => 'Can\'t move file'];
return $status;
}
$status = ['status' => 'success', 'url' => PROPERTY_IMG_TMP_DIR . '/' . $fileName, 'width' => $width, 'height' => $height, 'token' => $_SESSION['csrf_token']];
return $status;
}
示例2: generate
/**
* The hard stuff. Resizing an image while applying an appropriate background
* @param $sourceImage
* @param $targetImage
* @param $targetWidth
* @param $targetHeight
* @param int $quality
* @throws Exception
*/
public static function generate($sourceImage, $targetImage, $targetWidth, $targetHeight, $quality = 100)
{
// get source dimensions
list($sourceWidth, $sourceHeight, $sourceMimeType) = getimagesize($sourceImage);
// resolving mime type e.g. image/*
$imageType = image_type_to_mime_type($sourceMimeType);
// resolve Image Resource handler against the said image type and the source image path
$sourceImageResource = static::getImageResourceFromImageTypeAndFile($imageType, $sourceImage);
// resolve aspect-ratio maintained height and width for the thumbnail against source's dimensions and expected
// dimensions
list($calculatedTargetWidth, $calculatedTargetHeight) = static::resolveNewWidthAndHeight($sourceWidth, $sourceHeight, $targetWidth, $targetHeight);
// create an image with the aspect-ration maintained height and width, this will be used to resample the source
// image
$resampledImage = imagecreatetruecolor(round($calculatedTargetWidth), round($calculatedTargetHeight));
imagecopyresampled($resampledImage, $sourceImageResource, 0, 0, 0, 0, $calculatedTargetWidth, $calculatedTargetHeight, $sourceWidth, $sourceHeight);
// create an image of the thumbnail size we desire (this may be less than the aspect-ration maintained height
// and width
$targetImageResource = imagecreatetruecolor($targetWidth, $targetHeight);
// setup a padding color, in our case we use white.
$paddingColor = imagecolorallocate($targetImageResource, 255, 255, 255);
// paint the target image all in the padding color so the canvas is completely white.
imagefill($targetImageResource, 0, 0, $paddingColor);
// now copy the resampled aspect-ratio maintained resized thumbnail onto the white canvas
imagecopy($targetImageResource, $resampledImage, ($targetWidth - $calculatedTargetWidth) / 2, ($targetHeight - $calculatedTargetHeight) / 2, 0, 0, $calculatedTargetWidth, $calculatedTargetHeight);
// save the resized thumbnail.
if (!imagejpeg($targetImageResource, $targetImage, $quality)) {
throw new Exception("Unable to save new image");
}
}
示例3: output
/**
* Output the image to a browser
*/
function output()
{
self::processImage();
header('Content-Type: ' . image_type_to_mime_type($this->type));
flush();
imagejpeg($this->image, NULL, $this->quality);
}
示例4: image_type_to_extension
public function image_type_to_extension($imagetype)
{
if (empty($imagetype)) {
return false;
}
switch ($imagetype) {
case image_type_to_mime_type(IMAGETYPE_GIF):
return 'gif';
case image_type_to_mime_type(IMAGETYPE_JPEG):
return 'jpg';
case image_type_to_mime_type(IMAGETYPE_PNG):
return 'png';
case image_type_to_mime_type(IMAGETYPE_SWF):
return 'swf';
case image_type_to_mime_type(IMAGETYPE_PSD):
return 'psd';
case image_type_to_mime_type(IMAGETYPE_BMP):
return 'bmp';
case image_type_to_mime_type(IMAGETYPE_TIFF_II):
return 'tiff';
case image_type_to_mime_type(IMAGETYPE_TIFF_MM):
return 'tiff';
case 'image/pjpeg':
return 'jpg';
default:
return false;
}
}
示例5: thumb
/**
* 生成缩略图函数
* @param $filename string 源文件
* @param $dst_w int 目标的宽,px
* @param $dst_h int 目标的高,px 默认都为一半
* @param $savepath string 保存路径
* @param $ifdelsrc boolean 是否删除源文件
* @return 缩略图文件名
*/
function thumb($filename, $dst_w = null, $dst_h = null, $savepath = null, $ifdelsrc = false)
{
list($src_w, $src_h, $imagetype) = getimagesize($filename);
$scale = 0.5;
if (is_null($dst_w) || is_null($dst_h)) {
$dst_w = ceil($src_w * $scale);
$dst_h = ceil($src_h * $scale);
}
$mime = image_type_to_mime_type($imagetype);
$createfunc = str_replace('/', 'createfrom', $mime);
$outfunc = str_replace('/', null, $mime);
$src_image = $createfunc($filename);
$dst_image = imagecreatetruecolor($dst_w, $dst_h);
imagecopyresampled($dst_image, $src_image, 0, 0, 0, 0, $dst_w, $dst_h, $src_w, $src_h);
if (is_null($savepath)) {
$savepath = $_SERVER['DOCUMENT_ROOT'] . 'images/thumb';
}
if (!empty($savepath) && !is_dir($savepath)) {
mkdir($savepath, 0777, true);
}
$fileinfo = pathinfo($filename);
$savename = uniqid() . '.' . $fileinfo['extension'];
if (!empty($savepath)) {
$outfunc($dst_image, $savepath . '/' . $savename);
} else {
$outfunc($dst_image, $savename);
}
imagedestroy($src_image);
imagedestroy($dst_image);
if (!$ifdelsrc) {
unlink($filename);
}
return $savename;
}
示例6: thumb
/**
* 生成缩略图
* @param string $filename
* @param string $destination
* @param int $dst_w
* @param int $dst_h
* @param bool $isReservedSource
* @param number $scale
* @return string
*/
function thumb($filename, $destination = null, $dst_w, $dst_h = NULL, $isReservedSource = true)
{
list($src_w, $src_h, $imagetype) = getimagesize($filename);
if ($src_w <= $dst_w) {
$dst_w = $src_w;
$dst_h = $src_h;
}
if (is_null($dst_h)) {
$dst_h = scaling($src_w, $src_h, $dst_w);
}
$mime = image_type_to_mime_type($imagetype);
$createFun = str_replace("/", "createfrom", $mime);
$outFun = str_replace("/", null, $mime);
$src_image = $createFun($filename);
$dst_image = imagecreatetruecolor($dst_w, $dst_h);
imagecopyresampled($dst_image, $src_image, 0, 0, 0, 0, $dst_w, $dst_h, $src_w, $src_h);
if ($destination && !file_exists(dirname($destination))) {
mkdir(dirname($destination), 0777, true);
}
$dstFilename = $destination == null ? getUniName() . "." . getExt($filename) : $destination;
$outFun($dst_image, $dstFilename);
imagedestroy($src_image);
imagedestroy($dst_image);
if (!$isReservedSource) {
unlink($filename);
}
return $dstFilename;
}
示例7: getImageFromUrl
public static function getImageFromUrl($image_url)
{
try {
$mime = image_type_to_mime_type(exif_imagetype($image_url));
} catch (Exception $e) {
throw new MimeTypeException($e->getMessage());
}
//Get image based on mime and set to $im
switch ($mime) {
case 'image/jpeg':
$im = imagecreatefromjpeg($image_url);
break;
case 'image/gif':
$im = imagecreatefromgif($image_url);
break;
case 'image/png':
$im = imagecreatefrompng($image_url);
break;
case 'image/wbmp':
$im = imagecreatefromwbmp($image_url);
break;
default:
throw new MimeTypeException("An image of '{$mime}' mime type is not supported.");
break;
}
return $im;
}
示例8: fileupload_trigger_check
function fileupload_trigger_check()
{
if (intval(get_query_var('postform_fileupload')) == 1) {
if (!(get_option('bbp_5o1_toolbar_allow_image_uploads') && (is_user_logged_in() || get_option('bbp_5o1_toolbar_allow_anonymous_image_uploads')))) {
echo htmlspecialchars(json_encode(array("error" => __("You are not permitted to upload images.", 'bbp_5o1_toolbar'))), ENT_NOQUOTES);
exit;
}
require_once dirname(__FILE__) . '/includes/fileuploader.php';
// list of valid extensions, ex. array("jpeg", "xml", "bmp")
$allowedExtensions = array('jpg', 'jpeg', 'png', 'gif');
// Because using Extensions only is very bad.
$allowedMimes = array(IMAGETYPE_JPEG, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_GIF);
// max file size in bytes
$sizeLimit = bbp_5o1_images_panel::return_bytes(min(array(ini_get('post_max_size'), ini_get('upload_max_filesize'))));
$uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
$directory = wp_upload_dir();
$result = $uploader->handleUpload(trailingslashit($directory['path']));
$mime = exif_imagetype($result['file']);
if (!$mime || !in_array($mime, $allowedMimes)) {
$deleted = unlink($result['file']);
echo htmlspecialchars(json_encode(array("error" => __("Disallowed file type.", 'bbp_5o1_toolbar'))), ENT_NOQUOTES);
exit;
}
// Construct the attachment array
$attachment = array('post_mime_type' => $mime ? image_type_to_mime_type($mime) : '', 'guid' => trailingslashit($directory['url']) . $result['filename'], 'post_parent' => 0, 'post_title' => $result['name'], 'post_content' => 'Image uploaded for a forum topic or reply.');
// Save the data
$id = wp_insert_attachment($attachment, $result['file'], 0);
$result['id'] = $id;
$result['attachment'] = $attachment;
$result = array("success" => true, "file" => $attachment['guid']);
echo htmlspecialchars(json_encode($result), ENT_NOQUOTES);
exit;
}
}
示例9: actionShow
public function actionShow()
{
$nome_da_pasta = $_GET['path'];
$arquivo = $_GET['file'];
$largura = $_GET['width'];
$path = Yii::app()->fileManager->findFile($arquivo, $nome_da_pasta, $largura);
if (!is_null($path)) {
$info = getimagesize($path);
$mime = image_type_to_mime_type($info[2]);
switch ($mime) {
case "image/jpeg":
$image = imagecreatefromjpeg($path);
header("Content-Type: image/jpeg");
imagejpeg($image);
break;
case "image/png":
$image = imagecreatefrompng($path);
header("Content-Type: image/png");
imagepng($image);
break;
case "image/gif":
$image = imagecreatefromgif($path);
header("Content-Type: image/gif");
imagegif($image);
break;
}
}
}
示例10: thumb
function thumb($filename, $destination = null, $dst_w = null, $dst_h = null, $isReservedSource = false, $scale = 0.5)
{
list($src_w, $src_h, $imagetype) = getimagesize($filename);
if (is_null($dst_w) || is_null($dst_h)) {
$dst_w = ceil($src_w * $scale);
$dst_h = ceil($src_h * $scale);
}
$mime = image_type_to_mime_type($imagetype);
$createFun = str_replace("/", "createfrom", $mime);
$outFun = str_replace("/", null, $mime);
$src_image = $createFun($filename);
$dst_image = imagecreatetruecolor($dst_w, $dst_h);
imagecopyresampled($dst_image, $src_image, 0, 0, 0, 0, $dst_w, $dst_h, $src_w, $src_h);
//image_50/sdfsdkfjkelwkerjle.jpg
if ($destination && !file_exists(dirname($destination))) {
mkdir(dirname($destination), 0777, true);
}
$dstFilename = $destination == null ? getUniName() . "." . getExt($filename) : $destination;
$outFun($dst_image, $dstFilename);
imagedestroy($src_image);
imagedestroy($dst_image);
if (!$isReservedSource) {
unlink($filename);
}
return $dstFilename;
}
示例11: ReSize
/**
* Resize an image to the specified dimensions, placing the resulting
* image in the specified location. At least one of $newWidth or
* $newHeight must be specified.
*
* @param string $type Either 'thumb' or 'disp'
* @param integer $newWidth New width, in pixels
* @param integer $newHeight New height, in pixels
* @return string Blank if successful, error message otherwise.
*/
public static function ReSize($src, $dst, $newWidth = 0, $newHeight = 0)
{
global $_LGLIB_CONF;
// Calculate the new dimensions
$A = self::reDim($src, $newWidth, $newHeight);
if ($A === false) {
COM_errorLog("Invalid image {$src}");
return 'invalid image conversion';
}
list($sWidth, $sHeight, $dWidth, $dHeight) = $A;
// Get the mime type for the glFusion resizing functions
$mime_type = image_type_to_mime_type(exif_imagetype($src));
// Returns an array, with [0] either true/false and [1]
// containing a message.
$result = array();
if (function_exists(_img_resizeImage)) {
$result = _img_resizeImage($src, $dst, $sHeight, $sWidth, $dHeight, $dWidth, $mime_type);
} else {
$result[0] = false;
}
if ($result[0] == true) {
return '';
} else {
COM_errorLog("Failed to convert {$src} ({$sHeight} x {$sWidth}) to {$dst} ({$dHeight} x {$dWidth})");
return 'invalid image conversion';
}
}
示例12: upload
public function upload()
{
if ($this->entityName === null || $this->entityId === null) {
throw new \Exception('property entityName and entityId must be set to other than null');
}
$dir = $this->dir();
if (!file_exists($dir)) {
return false;
}
$path = $this->path();
$tmp = $this->uploadData['tmp_name'];
$check = getimagesize($tmp);
if ($check === false) {
return false;
}
switch ($check['mime']) {
case image_type_to_mime_type(IMAGETYPE_GIF):
case image_type_to_mime_type(IMAGETYPE_PNG):
case image_type_to_mime_type(IMAGETYPE_JPEG):
break;
default:
return false;
}
if (move_uploaded_file($tmp, $path)) {
$this->thumbnail();
return true;
}
return false;
}
示例13: resizeThumbnailImage
function resizeThumbnailImage($thumb_image_name, $image, $width, $height, $start_width, $start_height, $scale)
{
list($imagewidth, $imageheight, $imageType) = getimagesize($image);
$imageType = image_type_to_mime_type($imageType);
$newImageWidth = ceil($width * $scale);
$newImageHeight = ceil($height * $scale);
$newImage = imagecreatetruecolor($newImageWidth, $newImageHeight);
switch ($imageType) {
case "image/png":
case "image/x-png":
$source = imagecreatefrompng($image);
break;
}
imagecopyresampled($newImage, $source, 0, 0, $start_width, $start_height, $newImageWidth, $newImageHeight, $width, $height);
switch ($imageType) {
case "image/png":
case "image/x-png":
$transcol = imagecolorallocatealpha($newImage, 255, 0, 255, 127);
$trans = imagecolortransparent($newImage, $transcol);
imagefill($newImage, 0, 0, $transcol);
imagesavealpha($newImage, true);
imagealphablending($newImage, true);
imagepng($newImage, $thumb_image_name);
break;
}
chmod($thumb_image_name, 0777);
}
示例14: getImage
protected function getImage($image_url)
{
$this->url = $image_url;
$mime = image_type_to_mime_type(exif_imagetype($image_url));
$im;
//Get image based on mime and set to $im
switch ($mime) {
case 'image/jpeg':
$im = imagecreatefromjpeg($image_url);
break;
case 'image/gif':
$im = imagecreatefromgif($image_url);
break;
case 'image/png':
$im = imagecreatefrompng($image_url);
break;
case 'image/wbmp':
$im = imagecreatefromwbmp($image_url);
break;
default:
return NULL;
break;
}
$this->image = $im;
return $this;
}
示例15: action_preview2
public function action_preview2()
{
$dir = $this->uploads_dir();
// build image file name
$filename = $this->request->param('filename');
// check if file exists
if (!file_exists($filename) or !is_file($filename)) {
throw new HTTP_Exception_404('Picture not found');
}
$cachenamearr = explode('/', $filename);
$name = array_pop($cachenamearr);
$cachename = 'a2' . $name;
$cachename = str_replace($name, $cachename, $filename);
/** @var Image $image **/
// trying get picture preview from cache
if (($image = Cache::instance()->get($cachename)) === NULL) {
// create new picture preview
$image = Image::factory($filename)->resize(null, 50)->crop(50, 50)->render(NULL, 90);
// store picture in cache
Cache::instance()->set($cachename, $image, Date::MONTH);
}
// gets image type
$info = getimagesize($filename);
$mime = image_type_to_mime_type($info[2]);
// display image
$this->response->headers('Content-type', $mime);
$this->response->body($image);
}