/** * 构造函数 * @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]); } } }
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"); }
/** * {@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; }
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); } }
/** * 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; }
/** * 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 []; }
/** * 打开一张图像 * @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); } }
/** * 验证参数 */ 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); }
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; }
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; }
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(); }
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; }
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; } } }
/** * 构造函数 * @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]); } } }
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); } }
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); }
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; } }
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; }
/** * @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; }
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, '上传失败,请联系管理员'); } }
public function imageJsonAction($id) { $manager = $this->container->get('wucdbm_gallery.manager.images'); $image = $manager->getImage($id); $data = ['id' => $image->getId(), 'md5' => $image->getMd5(), 'date_uploaded' => $image->getDateUploaded()->format('Y-m-d H:i:s'), 'extension' => image_type_to_extension($image->getExtension()), 'width' => $image->getWidth(), 'height' => $image->getHeight(), 'name' => $image->getName(), 'alt' => $image->getAlt(), 'path' => $manager->getImagePath($image), 'url' => $manager->getImageUrl($image)]; return $this->json($data); }
/** * アップロードされた画像をリネームする * * @param string $tmp_name アップロードされたファイル * @return string 保存したパス */ function t2p_rename_media($tmp_name) { if (!file_exists($tmp_name) || !is_uploaded_file($tmp_name)) { return false; } list($usec, $sec) = explode(' ', microtime()); $filename = date('Ymd', intval($sec)) . substr($usec, 1); $path = T2P_UPLOAD_DIR . DIRECTORY_SEPARATOR . $filename; $success = false; if (move_uploaded_file($tmp_name, $path)) { $info = getimagesize($path); if ($info !== false) { $ext = image_type_to_extension($info[2]); if ($ext !== false) { if (rename($path, $path . $ext)) { $path .= $ext; $success = true; } } } } if ($success) { if (!T2P_DEBUG) { register_shutdown_function('unlink', $path); } return $path; } else { if (!T2P_DEBUG && file_exists($path)) { unlink($path); } return false; } }
private function setFile($file) { $errorCode = $file['error']; if ($errorCode === UPLOAD_ERR_OK) { $type = exif_imagetype($file['tmp_name']); if ($type) { $extension = image_type_to_extension($type); $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(); } 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); } }
private function getImageFileName($fileName) { if (@exif_imagetype($fileName)) { return sprintf("%f6", microtime(true)) . image_type_to_extension(exif_imagetype($fileName)); } else { return ''; } }
/** +---------------------------------------------------------- * 生成缩略图 +---------------------------------------------------------- * @static * @access public +---------------------------------------------------------- * @param string $image 原图 * @param string $type 图像格式 * @param string $thumbname 缩略图文件名 * @param string $maxWidth 宽度 * @param string $maxHeight 高度 * @param boolean $interlace 启用隔行扫描 +---------------------------------------------------------- * @return void +---------------------------------------------------------- */ static function thumb($image, $thumbname = '', $maxWidth = 200, $maxHeight = 50, $type = '', $interlace = true) { // 获取原图信息 $i_size = getimagesize($image); if ($i_size === false) { return false; } $info = array("width" => $i_size[0], "height" => $i_size[1], "type" => substr(image_type_to_extension($i_size[2]), 1)); $info['type'] = strtolower($info['type'] == 'jpg' ? 'jpeg' : $info['type']); $srcWidth = $info['width']; $srcHeight = $info['height']; $type = empty($type) ? $info['type'] : ($type == 'jpg' ? 'jpeg' : strtolower($type)); $interlace = $interlace ? 1 : 0; $scale = min($maxWidth / $srcWidth, $maxHeight / $srcHeight); // 计算缩放比例 if ($scale >= 1) { // 超过原图大小不再缩略 $width = $srcWidth; $height = $srcHeight; } else { // 缩略图尺寸 $width = (int) ($srcWidth * $scale); $height = (int) ($srcHeight * $scale); } // 载入原图 $createFun = 'ImageCreateFrom' . $type; $srcImg = $createFun($image); //创建缩略图 if ($type != 'gif' && function_exists('imagecreatetruecolor')) { $thumbImg = imagecreatetruecolor($width, $height); } else { $thumbImg = imagecreate($width, $height); } // 复制图片 if (function_exists("ImageCopyResampled")) { imagecopyresampled($thumbImg, $srcImg, 0, 0, 0, 0, $width, $height, $srcWidth, $srcHeight); } else { imagecopyresized($thumbImg, $srcImg, 0, 0, 0, 0, $width, $height, $srcWidth, $srcHeight); } if ('gif' == $type || 'png' == $type) { $background_color = imagecolorallocate($thumbImg, 0, 255, 0); // 指派一个绿色 imagecolortransparent($thumbImg, $background_color); // 设置为透明色,若注释掉该行则输出绿色的图 } elseif ('jpeg' == $type) { // 对jpeg图形设置隔行扫描 imageinterlace($thumbImg, $interlace); } // 生成图片 $imageFun = 'image' . $type; if (empty($thumbname)) { $imageFun($thumbImg); } else { $imageFun($thumbImg, $thumbname); } imagedestroy($thumbImg); imagedestroy($srcImg); }
/** * Create a new movie. * @param integer $parent_id id of parent album * @param string $filename path to the photo file on disk * @param string $name the filename to use for this photo in the album * @param integer $title the title of the new photo * @param string $description (optional) the longer description of this photo * @return Item_Model */ static function create($parent, $filename, $name, $title, $description = null, $owner_id = null) { if (!$parent->loaded || !$parent->is_album()) { throw new Exception("@todo INVALID_PARENT"); } if (!is_file($filename)) { throw new Exception("@todo MISSING_MOVIE_FILE"); } if (strpos($name, "/")) { throw new Exception("@todo NAME_CANNOT_CONTAIN_SLASH"); } // We don't allow trailing periods as a security measure // ref: http://dev.kohanaphp.com/issues/684 if (rtrim($name, ".") != $name) { throw new Exception("@todo NAME_CANNOT_END_IN_PERIOD"); } $movie_info = movie::getmoviesize($filename); // Force an extension onto the name $pi = pathinfo($filename); if (empty($pi["extension"])) { $pi["extension"] = image_type_to_extension($movie_info[2], false); $name .= "." . $pi["extension"]; } $movie = ORM::factory("item"); $movie->type = "movie"; $movie->title = $title; $movie->description = $description; $movie->name = $name; $movie->owner_id = $owner_id ? $owner_id : user::active(); $movie->width = $movie_info[0]; $movie->height = $movie_info[1]; $movie->mime_type = strtolower($pi["extension"]) == "mp4" ? "video/mp4" : "video/x-flv"; $movie->thumb_dirty = 1; $movie->resize_dirty = 1; $movie->sort_column = "weight"; $movie->rand_key = (double) mt_rand() / (double) mt_getrandmax(); // Randomize the name if there's a conflict while (ORM::Factory("item")->where("parent_id", $parent->id)->where("name", $movie->name)->find()->id) { // @todo Improve this. Random numbers are not user friendly $movie->name = rand() . "." . $pi["extension"]; } // This saves the photo $movie->add_to_parent($parent); // If the thumb or resize already exists then rename it if (file_exists($movie->resize_path()) || file_exists($movie->thumb_path())) { $movie->name = $pi["filename"] . "-" . rand() . "." . $pi["extension"]; $movie->save(); } copy($filename, $movie->file_path()); module::event("item_created", $movie); // Build our thumbnail graphics::generate($movie); // If the parent has no cover item, make this it. if (access::can("edit", $parent) && $parent->album_cover_item_id == null) { item::make_album_cover($movie); } return $movie; }
/** * 加载图片创建临时图像 */ public function load_image($src) { $imagesize = getimagesize($src); $info = array('width' => $imagesize[0], 'height' => $imagesize[1], 'extension' => image_type_to_extension($imagesize[2], false)); $function = 'imagecreatefrom' . $info['extension']; //统一放到$info数组中 $info['image'] = $function($src); return $info; }
/** * Return the width, height, mime_type and extension of the given image file. */ static function get_file_metadata($file_path) { $image_info = getimagesize($file_path); $width = $image_info[0]; $height = $image_info[1]; $mime_type = $image_info["mime"]; $extension = image_type_to_extension($image_info[2], false); return array($width, $height, $mime_type, $extension); }
public function imagemark($water_url, $local, $alpha) { $info2 = getimagesize($water_url); $info2 = array('width' => $info2[0], 'height' => $info2[1], 'type' => image_type_to_extension($info2[2], false), 'mime' => $info2['mime']); $fun2 = "imagecreatefrom{$info2['type']}"; $water = $fun2($water_url); imagecopymerge($this->image, $water, $local['x'], $local['y'], 0, 0, $info2['width'], $info2['height'], $alpha); imagedestroy($water); }
public function imageMark($source, $local, $alpha) { $infoMark = getimagesize($source); $MarkType = image_type_to_extension($infoMark[2], false); $fun2 = "imagecreatefrom{$MarkType}"; $Mark = $fun2($source); imagecopymerge($this->image, $Mark, $local['x'], $local['y'], 0, 0, $infoMark[0], $infoMark[1], $alpha); imagedestroy($Mark); }