本文整理汇总了PHP中image_type_to_extension函数的典型用法代码示例。如果您正苦于以下问题:PHP image_type_to_extension函数的具体用法?PHP image_type_to_extension怎么用?PHP image_type_to_extension使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了image_type_to_extension函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* 构造函数
* @param array $files 要处理的图片列表
*/
public function __construct(array $files = array())
{
//名称生成方式
$this->namecall = function ($name) {
return 'Other/' . $name . '-' . md5($name);
};
//设置文件信息
foreach ($files as $key => $file) {
//写入临时文件获取文件名
$f = new \SaeFetchurl();
$filename = tempnam(SAE_TMP_PATH, "SAE_IMAGE");
$data = $f->fetch(str_replace(' ', '%20', $file));
if (!file_put_contents($filename, $data)) {
continue;
}
//取得文件的大小信息
if (false !== ($this->infos[$file] = getimagesize($filename))) {
//取得扩展名
//支持格式 see http://www.php.net/manual/zh/function.exif-imagetype.php
$this->infos[$file]['ext'] = image_type_to_extension(exif_imagetype($filename), 0);
$this->infos[$file]['data'] = $data;
//如果不在允许的图片类型范围内
if (!in_array($this->infos[$file]['ext'], $this->exts)) {
unset($this->infos[$file]);
}
} else {
//如果获取信息失败则取消设置
unset($this->infos[$file]);
}
}
}
开发者ID:lunnlew,项目名称:Norma_Code,代码行数:35,代码来源:SAEImage.php
示例2: saveThumb
function saveThumb()
{
$targ_w = $targ_h = 120;
//头像的高度和宽度
$jpeg_quality = 100;
$src = $_POST['bigImage'];
//获取图片的扩展名。来选择使用什么函数
if ($arr = @getimagesize($src)) {
$ext = image_type_to_extension($arr[2], false);
} else {
$this->error('对不起,GD库不存在或远程图片不存在');
exit;
}
$func = $ext != 'jpg' ? 'imagecreatefrom' . $ext : 'imagecreatefromjpeg';
$img_r = call_user_func($func, $src);
//函数已经确定
//开始切割头像
$dst_r = ImageCreateTrueColor($targ_w, $targ_h);
$x = $targ_h / $_POST['txt_Zoom'];
imagecopyresampled($dst_r, $img_r, 0, 0, $_POST['txt_left'] / $_POST['txt_Zoom'], $_POST['txt_top'] / $_POST['txt_Zoom'], $targ_w, $targ_h, $x, $x);
//将头像保存
$path = ROOT_PATH . "/data/thumb/";
$filename = $path . 'xxx_s.jpg';
imagejpeg($dst_r, $filename);
$this->redirect("/Home/index");
}
开发者ID:wangping1987,项目名称:dhfriendluck,代码行数:26,代码来源:ExpAction.class.php
示例3: execute
/**
* {@inheritdoc}
*/
protected function execute(array $arguments)
{
// Store the original resource.
$original_res = $this->getToolkit()->getResource();
// Prepare the canvas.
$data = array('width' => $arguments['width'], 'height' => $arguments['height'], 'extension' => image_type_to_extension($this->getToolkit()->getType(), FALSE), 'transparent_color' => $this->getToolkit()->getTransparentColor(), 'is_temp' => TRUE);
if (!$this->getToolkit()->apply('create_new', $data)) {
return FALSE;
}
// Fill the canvas with required color.
$data = array('rectangle' => new PositionedRectangle($arguments['width'], $arguments['height']), 'fill_color' => $arguments['canvas_color']);
if (!$this->getToolkit()->apply('draw_rectangle', $data)) {
return FALSE;
}
// Overlay the current image on the canvas.
imagealphablending($original_res, TRUE);
imagesavealpha($original_res, TRUE);
imagealphablending($this->getToolkit()->getResource(), TRUE);
imagesavealpha($this->getToolkit()->getResource(), TRUE);
if (imagecopy($this->getToolkit()->getResource(), $original_res, $arguments['x_pos'], $arguments['y_pos'], 0, 0, imagesx($original_res), imagesy($original_res))) {
imagedestroy($original_res);
return TRUE;
} else {
// In case of failure, destroy the temporary resource and restore
// the original one.
imagedestroy($this->getToolkit()->getResource());
$this->getToolkit()->setResource($original_res);
}
return FALSE;
}
开发者ID:andrewl,项目名称:andrewlnet,代码行数:33,代码来源:SetCanvas.php
示例4: setFile
private function setFile($file, $ImageName)
{
//echo $_SERVER['DOCUMENT_ROOT'];
//exit;
$root_url = $_SERVER['DOCUMENT_ROOT'] . "/branboxAdmin/";
$errorCode = $file['error'];
if ($errorCode === UPLOAD_ERR_OK) {
$type = exif_imagetype($file['tmp_name']);
if ($type) {
$extension = image_type_to_extension($type);
$src = $root_url . 'upload/' . $ImageName . '.original' . $extension;
//$src = 'img/' . date('YmdHis') . '.original' . $extension;
if ($type == IMAGETYPE_GIF || $type == IMAGETYPE_JPEG || $type == IMAGETYPE_PNG) {
if (file_exists($src)) {
unlink($src);
}
$result = move_uploaded_file($file['tmp_name'], $src);
if ($result) {
$this->src = $src;
$this->type = $type;
$this->extension = $extension;
$this->setDst($ImageName);
} else {
$this->msg = 'Failed to save file';
}
} else {
$this->msg = 'Please upload image with the following types: JPG, PNG, GIF';
}
} else {
$this->msg = 'Please upload image file';
}
} else {
$this->msg = $this->codeToMessage($errorCode);
}
}
开发者ID:Gobi09,项目名称:branboxAdmin,代码行数:35,代码来源:crop_helper.php
示例5: open
/**
* Open an image
*
* @param string $file
* @return Engine_Image_Adapter_Gd
* @throws Engine_Image_Adapter_Exception If unable to open
*/
public function open($file)
{
// Get image info
$info = @getimagesize($file);
if (!$info) {
throw new Engine_Image_Adapter_Exception(sprintf("File \"%s\" is not an image or does not exist", $file));
}
// Check if we can open the file
self::_isSafeToOpen($info[0], $info[1]);
// Detect type
$type = ltrim(strrchr('.', $file), '.');
if (!$type) {
$type = image_type_to_extension($info[2], false);
}
$type = strtolower($type);
// Check support
self::_isSupported($type);
$function = 'imagecreatefrom' . $type;
if (!function_exists($function)) {
throw new Engine_Image_Adapter_Exception(sprintf('Image type "%s" is not supported', $type));
}
// Open
$this->_resource = $function($file);
if (!$this->_resource) {
throw new Engine_Image_Adapter_Exception("Unable to open image");
}
$this->_info = new stdClass();
$this->_info->type = $type;
$this->_info->file = $file;
$this->_info->width = $info[0];
$this->_info->height = $info[1];
return $this;
}
开发者ID:robeendey,项目名称:ce,代码行数:40,代码来源:Gd.php
示例6: actionUploadImage
/**
* Upload the image
*/
public function actionUploadImage()
{
Yii::$app->response->format = Response::FORMAT_JSON;
if (!empty($_FILES['file']['tmp_name'])) {
if ($image = Image::load($_FILES['file']['tmp_name'], $this->_module->imageDriver)) {
if (!empty($this->_module->maxImageResolution)) {
$resolution = explode('x', strtolower($this->_module->maxImageResolution));
$width = empty($resolution[0]) ? null : $resolution[0];
$height = empty($resolution[1]) ? null : $resolution[1];
if ($image->width > $width && $image->height > $height) {
$image->resize($width, $height, 'auto');
}
}
$extension = strtolower(image_type_to_extension($image->type, true));
if (!in_array($extension, ['.jpg', '.gif', '.png'])) {
$extension = '.jpg';
}
$filename = $this->uniqueRandomFilename($this->_module->imageUploadPath, $extension);
if ($image->save("{$this->_module->imageUploadPath}/{$filename}{$extension}")) {
return ['filelink' => "{$this->_module->imageBaseUrl}/{$filename}{$extension}"];
}
}
}
return [];
}
开发者ID:mervick,项目名称:yii2-redactor-js,代码行数:28,代码来源:DefaultController.php
示例7: open
/**
* 打开一张图像
* @param string $imgname 图像路径
*/
public function open($imgname)
{
//检测图像文件
if (!is_file($imgname)) {
throw new Exception('不存在的图像文件');
}
//获取图像信息
$info = getimagesize($imgname);
//检测图像合法性
if (false === $info || IMAGETYPE_GIF === $info[2] && empty($info['bits'])) {
throw new Exception('非法图像文件');
}
//设置图像信息
$this->info = array('width' => $info[0], 'height' => $info[1], 'type' => image_type_to_extension($info[2], false), 'mime' => $info['mime']);
//销毁已存在的图像
empty($this->img) || imagedestroy($this->img);
//打开图像
if ('gif' == $this->info['type']) {
require 'GIF.class.php';
$class = 'GIF';
$this->gif = new $class($imgname);
$this->img = imagecreatefromstring($this->gif->image());
} else {
$fun = "imagecreatefrom{$this->info['type']}";
$this->img = $fun($imgname);
}
}
开发者ID:bibyzhang,项目名称:produce_cms,代码行数:31,代码来源:Gd.class.php
示例8: run
/**
* 验证参数
*/
public function run($JSconfig, $PHPconfig)
{
if (!isset($JSconfig["url"]) || !isset($JSconfig["R"]) || !isset($JSconfig["X"]) || !isset($JSconfig["Y"]) || !isset($JSconfig["IW"]) || !isset($JSconfig["IH"]) || !isset($JSconfig["P"]) || !isset($JSconfig["FW"]) || !isset($JSconfig["FH"])) {
$this->erro = "服务端接收到的数据缺少参数";
return false;
}
foreach ($JSconfig as $k => $v) {
if ($k !== "url") {
if (!is_numeric($v)) {
$this->erro = "传递的参数有误";
return false;
}
}
}
//验证是否为字除了url
if ($PHPconfig["proportional"] !== $JSconfig["P"]) {
$this->erro = "JS设置的比例和PHP设置不一致";
return false;
}
list($w, $h, $type) = getimagesize($JSconfig["url"]);
//验证是否真图片!
$this->imagesuffix = image_type_to_extension($type);
$type_array = array(".jpeg", ".gif", ".png", ".jpg");
if (!in_array(strtolower($this->imagesuffix), $type_array)) {
$this->erro = "无法读取图片";
return false;
}
if ($JSconfig["R"] == -90 || $JSconfig["R"] == -270) {
list($w, $h) = array($h, $w);
}
return $this->createshear($w, $h, $type, $JSconfig);
}
开发者ID:medolyWu,项目名称:lvzhisha,代码行数:35,代码来源:ShearPhoto.class.php
示例9: __construct
public function __construct($file)
{
if (!Image_GD::$_checked) {
// Run the install check
Image_GD::check();
}
parent::__construct($file);
// Set the image creation function name
switch ($this->type) {
case IMAGETYPE_JPEG:
$create = 'imagecreatefromjpeg';
break;
case IMAGETYPE_GIF:
$create = 'imagecreatefromgif';
break;
case IMAGETYPE_PNG:
$create = 'imagecreatefrompng';
break;
}
if (!isset($create) or !function_exists($create)) {
throw new Kohana_Exception('Installed GD does not support :type images', array(':type' => image_type_to_extension($this->type, FALSE)));
}
// Save function for future use
$this->_create_function = $create;
// Save filename for lazy loading
$this->_image = $this->file;
}
开发者ID:homm,项目名称:image,代码行数:27,代码来源:gd.php
示例10: get
public function get($file_link)
{
if ($imageSizes = @getimagesize($file_link)) {
return ['width' => $imageSizes[0], 'height' => $imageSizes[1], 'mime' => $imageSizes['mime'], 'extension' => image_type_to_extension($imageSizes[2], false)];
}
return false;
}
开发者ID:vincoweb,项目名称:easy-php-file-info,代码行数:7,代码来源:ImageInfo.php
示例11: share
public function share()
{
$data['content'] = urldecode($_GET['title']) . ' ' . urldecode($_GET['url']) . ' ';
$data['source'] = urldecode($_GET['sourceTitle']);
$data['sourceUrl'] = urldecode($_GET['sourceUrl']);
// 获取远程图片 => 生成临时图片
if ($pic_url = urldecode($_GET['picUrl'])) {
// http://d.hiphotos.baidu.com/image/w%3D2048/sign=31cded21bb12c8fcb4f3f1cdc83b9345/ac4bd11373f0820219e90e3e49fbfbedab641bb3.jpg
$imageInfo = getimagesize($pic_url);
$imageType = strtolower(substr(image_type_to_extension($imageInfo[2]), 1));
if ('bmp' != $imageType) {
// 禁止BMP格式的图片
$save_path = SITE_PATH . '/data/uploads/temp';
// 临时图片地址
$filename = md5($pic_url) . '.' . $imageType;
// 重复刷新时, 生成的文件名应一致
$img = file_get_contents($pic_url);
$filepath = $save_path . '/' . $filename;
$result = file_put_contents($filepath, $img);
if ($result) {
$data['type'] = 1;
$data['type_data'] = 'temp/' . $filename;
}
}
}
// 权限控制
$type = array('face', 'at', 'image', 'video', 'file', 'topic', 'contribute');
foreach ($type as $value) {
$data['actions'][$value] = in_array($value, array('face', 'image')) ? true : false;
}
$this->assign($data);
$this->display();
}
开发者ID:songhongyu,项目名称:THINKSNS,代码行数:33,代码来源:WidgetAction.class.php
示例12: upload
public function upload($file)
{
$out = ['res' => false, 'error' => '', 'path' => '', 'ext' => ''];
if (is_uploaded_file($file['tmp_name'])) {
$file_tmp_name = $file['tmp_name'];
$file_name = $file['name'];
$mime = exif_imagetype($file_tmp_name);
if ($mime === false) {
$out['error'] = "Файл не является изображением " . $mime;
} else {
$name = Helpers::make_translit(pathinfo($file_name)['filename']);
$dir = '/images/';
$ext = image_type_to_extension($mime);
$full_name = $name . $ext;
$dir = '/images/';
$j = 0;
while (file_exists(__DIR__ . '/..' . $dir . $full_name)) {
++$j;
$full_name = $name . '_' . $j . $ext;
}
$full_path = $dir . $full_name;
if (move_uploaded_file($file_tmp_name, __DIR__ . '/..' . $full_path)) {
$out['res'] = true;
$out['path'] = $full_path;
$out['ext'] = $ext;
} else {
$out['error'] = "Произошла ошибка, попробуйте еще раз";
}
}
} else {
$out['error'] = "Сервер отклюнил картинку";
}
return $out;
}
开发者ID:annasoal,项目名称:newsite,代码行数:34,代码来源:Image.php
示例13: _load_data
function _load_data()
{
if (!$this->loaded && $this->havegd) {
if (!empty($this->filename) && is_file($this->filename)) {
$this->format = strtolower(substr($this->filename, strrpos($this->filename, '.') + 1));
list($this->width, $this->height, $type) = getimagesize($this->filename);
if (function_exists("image_type_to_extension")) {
$this->format = image_type_to_extension($type, false);
} else {
$tmp = image_type_to_mime_type($type);
$this->format = strtolower(substr($tmp, strrpos($tmp, "/") + 1));
}
if ($this->is_supported($this->format)) {
if ($this->format == 'jpg') {
$this->format = 'jpeg';
}
$this->data = call_user_func('imagecreatefrom' . $this->format, $this->filename);
$this->loaded = true;
}
} elseif (!empty($this->data)) {
$this->data = imagecreatefromstring($this->data);
$this->loaded = true;
}
}
}
开发者ID:railfuture,项目名称:tiki-website,代码行数:25,代码来源:gd.php
示例14: __construct
/**
* 构造函数
* @param array $files 要处理的图片列表
*/
public function __construct(array $files = array())
{
//名称生成方式
$this->namecall = function ($name) {
return 'Other/' . $name . '-' . md5($name);
};
//设置文件信息
foreach ($files as $key => $file) {
//对文件名中的空格做处理
$filename = str_replace(' ', '%20', $file);
//取得文件的大小信息
if (false !== ($this->infos[$file] = getimagesize($filename))) {
//取得扩展名
//支持格式 see http://www.php.net/manual/zh/function.exif-imagetype.php
$this->infos[$file]['ext'] = image_type_to_extension(exif_imagetype($filename), 0);
//如果不在允许的图片类型范围内
if (!in_array($this->infos[$file]['ext'], $this->exts)) {
unset($this->infos[$file]);
}
} else {
//如果获取信息失败则取消设置
unset($this->infos[$file]);
}
}
}
开发者ID:lunnlew,项目名称:Norma_Code,代码行数:29,代码来源:LAEGDImage.php
示例15: setFile
private function setFile($file, $file_name)
{
$errorCode = $file['error'];
if ($errorCode === UPLOAD_ERR_OK) {
$type = exif_imagetype($file['tmp_name']);
if ($type) {
$extension = image_type_to_extension($type);
$src = 'img/' . $file_name . '.original' . $extension;
//上传原图
if ($type == IMAGETYPE_GIF || $type == IMAGETYPE_JPEG || $type == IMAGETYPE_PNG) {
if (file_exists($src)) {
unlink($src);
}
$result = move_uploaded_file($file['tmp_name'], $src);
if ($result) {
$this->src = $src;
$this->type = $type;
$this->extension = $extension;
$this->setDst($file_name);
} else {
$this->msg = '上传图片失败';
}
} else {
$this->msg = '请上传支持的格式,包括JPG, PNG, GIF';
}
} else {
$this->msg = '请上传有效的图片';
}
} else {
$this->msg = $this->codeToMessage($errorCode);
}
}
开发者ID:sunyang3721,项目名称:php-crop-avatar,代码行数:32,代码来源:crop.php
示例16: __construct
public function __construct($file)
{
if (!Image_GD::$_checked) {
// Run the install check
Image_GD::check();
}
parent::__construct($file);
// Set the image creation function name
switch ($this->type) {
case IMAGETYPE_JPEG:
$create = 'imagecreatefromjpeg';
break;
case IMAGETYPE_GIF:
$create = 'imagecreatefromgif';
break;
case IMAGETYPE_PNG:
$create = 'imagecreatefrompng';
break;
}
if (!isset($create) or !function_exists($create)) {
throw new Kohana_Exception('Installed GD does not support :type images', array(':type' => image_type_to_extension($this->type, FALSE)));
}
// Open the temporary image
$this->_image = $create($this->file);
// Preserve transparency when saving
imagesavealpha($this->_image, TRUE);
}
开发者ID:joelpittet,项目名称:image,代码行数:27,代码来源:gd.php
示例17: load
function load($filename)
{
$image_info = getimagesize($filename);
$this->image_type = $image_info[2];
$this->filename = $filename;
switch ($this->image_type) {
case IMAGETYPE_JPEG:
$this->image = @imagecreatefromjpeg($filename);
break;
case IMAGETYPE_GIF:
$this->image = @imagecreatefromgif($filename);
break;
case IMAGETYPE_PNG:
$this->image = @imagecreatefrompng($filename);
break;
case IMAGETYPE_WBMP:
$this->image = @imagecreatefromwbmp($filename);
break;
default:
$this->image = false;
}
if ($this->image) {
$this->extension = @image_type_to_extension($this->image_type, false);
return true;
} else {
$this->extension = '';
syslog(LOG_INFO, "SimpleImage::load(): Image not loaded, {$filename}, {$this->image_type}");
return false;
}
}
开发者ID:GallardoAlba,项目名称:Meneame,代码行数:30,代码来源:simpleimage.php
示例18: upload
public function upload($tmp, $uniqid)
{
$path = $this->getPath();
if ($this->canUpload($tmp)) {
$info = getimagesize($tmp);
if (!$info) {
$swc = false;
if ($fp = fopen($tmp, 'rb')) {
$header = fread($fp, 20);
$swc = substr($header, 0, 3) === 'CWS';
fclose($fp);
}
$ext = $swc ? '.swf' : '.dat';
} else {
$ext = image_type_to_extension($info[2], true);
}
$basename = $uniqid . $ext;
$filename = $path . $basename;
if (copy($tmp, $filename)) {
$this->setValue($basename);
return true;
}
}
return false;
}
开发者ID:ExceptVL,项目名称:kanon,代码行数:25,代码来源:imageFilenameProperty.php
示例19: pathWithExtension
/**
* @param $path
* @return string
*/
protected function pathWithExtension($path)
{
$info = getimagesize($path);
//add the extension based on the image type
$finalPath = $path . image_type_to_extension($info[2]);
return $finalPath;
}
开发者ID:jaffle-be,项目名称:framework,代码行数:11,代码来源:CheckGravatarImage.php
示例20: actionImage
public function actionImage()
{
$params = Yii::app()->params;
$file = CUploadedFile::getInstanceByName('imgFile');
if ($file === null || $file->getHasError()) {
$this->jsonReturn($file === null ? 1 : $file->getError(), '上传失败,请联系管理员');
}
$imagesize = getimagesize($file->getTempName());
if ($imagesize === false) {
$this->jsonReturn(1, '请上传正确格式的图片');
}
$basePath = $params->staticPath;
$extension = image_type_to_extension($imagesize[2]);
$md5 = md5(file_get_contents($file->getTempName()));
$filename = $md5 . $extension;
$dirname = 'upload/' . $md5[0] . '/';
$fullPath = $params->staticPath . $dirname . $filename;
$fullDir = dirname($fullPath);
if (!is_dir($fullDir)) {
mkdir($fullDir, 0755, true);
}
if (file_exists($fullPath) || $file->saveAs($fullPath)) {
$url = $params->staticUrlPrefix . $dirname . $filename;
$this->jsonReturn(0, '', $url);
} else {
$this->jsonReturn(1, '上传失败,请联系管理员');
}
}
开发者ID:sunshy360,项目名称:cubingchina,代码行数:28,代码来源:UploadController.php
注:本文中的image_type_to_extension函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论