/** * 上传信息图片 * @author 肖飞 * @param array $arrFile 图片文件信息数组$_FILES * @param int $num 图片的标号(用于多图上传) * @param array $FileListPicSize 缩略图压缩的尺寸(像素数组,存放目录小图s,中图m,例如:array('s'=>array(50,50),'m'=>array(100,100));) * @param int $FileSourPicSize 原图压缩的尺寸(像素数组,存放目录b,例如:array(600,600)) * @param int $intInfoID 相关数据记录ID,标示新增还是修改。 * @param int $intFetch 是否来自采集 * @param bool $blTime 新文件名是否使用时间戳 * @param string $FileExt 文件后缀名 * @return string */ public function uploadInfoImage($arrFile, $num = null, $FileListPicSize = 0, $FileSourPicSize = 0, $intInfoID = 0, $intFetch = 0, $blTime = true, $FileExt = '') { if ($arrFile['error'] != 0) { switch ($arrFile['error']) { case 1: $strError = '文件超过了 php.ini 中 upload_max_filesize 选项限制的值'; break; case 2: $strError = '文件的大小超过了 HTML 表单中 MAX_FILE_SIZE 选项指定的值'; break; case 3: $strError = '文件只有部分被上传'; break; case 4: $strError = '没有文件被上传'; break; case 6: $strError = '找不到临时文件夹'; break; case 7: $strError = '文件写入失败'; break; } check::AlertExit('文件上传错误!(' . $strError . ')', -1); } if ($arrFile['name']) { $strFileType = strtolower($arrFile['type']); if (!in_array($strFileType, array('image/jpg', 'image/jpeg', 'image/gif', 'image/pjpeg', 'image/png', 'image/x-png'))) { check::AlertExit('文件类型不符合要求(' . $arrFile['type'] . ')', -1); } } if ($intInfoID == 0) { $intID = $this->getMaxID(); } else { $intID = $intInfoID; } $strDir = ceil($intID / $this->arrGCache['cache_filenum']); if (!is_dir($this->arrGPic['FileSavePath'])) { @mkdir($this->arrGPic['FileSavePath']); @chmod($this->arrGPic['FileSavePath'], 0777); } $strMakeDir = $this->arrGPic['FileSavePath'] . 'b/'; if (!is_dir($strMakeDir)) { @mkdir($strMakeDir); @chmod($strMakeDir, 0777); } $strMakeDir = $strMakeDir . $strDir; if (!is_dir($strMakeDir)) { @mkdir($strMakeDir); @chmod($strMakeDir, 0777); } if ($FileExt == '') { $FileExt = strtolower(strrchr($arrFile['name'], '.')); } //取得上传文件扩展名 if ($blTime) { $strTime = time(); } else { $strTime = ''; } if (!empty($num)) { $strPhoto = $strDir . '/' . $intID . '_' . $strTime . "_{$num}" . $FileExt; //存入数据库的图片访问路径 $strPicName = $strMakeDir . '/' . $intID . '_' . $strTime . "_{$num}" . $FileExt; //新图片路径及名称 } else { $strPhoto = $strDir . '/' . $intID . '_' . $strTime . $FileExt; $strPicName = $strMakeDir . '/' . $intID . '_' . $strTime . $FileExt; } if (!empty($FileListPicSize)) { //所有的图都生成缩略图 $strMakeSmallDir = $this->arrGPic['FileSavePath'] . 's/'; if (!is_dir($strMakeSmallDir)) { @mkdir($strMakeSmallDir); @chmod($strMakeSmallDir, 0777); } $strMakeSmallDir = $strMakeSmallDir . $strDir; if (!is_dir($strMakeSmallDir)) { @mkdir($strMakeSmallDir); @chmod($strMakeSmallDir, 0777); } $strMakeMiddleDir = $this->arrGPic['FileSavePath'] . 'm/'; if (!is_dir($strMakeMiddleDir)) { @mkdir($strMakeMiddleDir); @chmod($strMakeMiddleDir, 0777); } $strMakeMiddleDir = $strMakeMiddleDir . $strDir; if (!is_dir($strMakeMiddleDir)) { @mkdir($strMakeMiddleDir); @chmod($strMakeMiddleDir, 0777); } if (!empty($num)) { $strSmallPicName = $strMakeSmallDir . '/' . $intID . '_' . $strTime . "_{$num}" . $FileExt; $strMiddlePicName = $strMakeMiddleDir . '/' . $intID . '_' . $strTime . "_{$num}" . $FileExt; } else { $strSmallPicName = $strMakeSmallDir . '/' . $intID . '_' . $strTime . $FileExt; $strMiddlePicName = $strMakeMiddleDir . '/' . $intID . '_' . $strTime . $FileExt; } $arrTemp = getimagesize($arrFile['tmp_name']); $arrImageInfo["width"] = $arrTemp[0]; $arrImageInfo["height"] = $arrTemp[1]; if (is_array($FileListPicSize)) { //生成s小缩略图 if (!empty($FileListPicSize['s'])) { Asido::Driver('gd'); $i1 = Asido::Image($arrFile['tmp_name'], $strSmallPicName); if ($FileListPicSize['s'][0] == 0) { //小图宽0 if ($FileListPicSize['s'][1] > 0) { Asido::height($i1, $FileListPicSize['s'][1]); $i1->save(ASIDO_OVERWRITE_ENABLED); } } elseif ($FileListPicSize['s'][1] == 0) { //小图高0 Asido::width($i1, $FileListPicSize['s'][0]); $i1->save(ASIDO_OVERWRITE_ENABLED); } elseif (Asido::resize($i1, $FileListPicSize['s'][0], $FileListPicSize['s'][1], $this->arrGPic['zoomMode'])) { $i1->save(ASIDO_OVERWRITE_ENABLED); } else { check::AlertExit($strSmallPicName . '缩略图生成错误!', -1); } } //生成m中缩略图 if (!empty($FileListPicSize['m'])) { Asido::Driver('gd'); $i1 = Asido::Image($arrFile['tmp_name'], $strMiddlePicName); if ($FileListPicSize['m'][0] == 0) { if ($FileListPicSize['m'][1] > 0) { Asido::height($i1, $FileListPicSize['m'][1]); $i1->save(ASIDO_OVERWRITE_ENABLED); } } elseif ($FileListPicSize['m'][1] == 0) { Asido::width($i1, $FileListPicSize['m'][0]); $i1->save(ASIDO_OVERWRITE_ENABLED); } elseif (Asido::resize($i1, $FileListPicSize['m'][0], $FileListPicSize['m'][1], $this->arrGPic['zoomMode'])) { $i1->save(ASIDO_OVERWRITE_ENABLED); } else { check::AlertExit($strMiddlePicName . '缩略图生成错误!', -1); } } } else { if (!empty($FileListPicSize)) { check::AlertExit('缩略图的定义格式已经升级,请检查var.inc.php中$arrGPic[FileListPicSize]的定义!', -1); } } } if (!empty($FileSourPicSize)) { //原图容量>最大容量设定,就自动压缩原图 if ($intFetch) { copy($arrFile['tmp_name'], $strPicName); } else { move_uploaded_file($arrFile['tmp_name'], $strPicName); } if (is_array($FileSourPicSize)) { Asido::Driver('gd'); $i1 = Asido::Image($strPicName, $strPicName); if ($FileSourPicSize[0] == 0) { //设定宽=0,则不定宽,定高压缩 if ($FileSourPicSize[1] > 0 && $FileSourPicSize[1] < $arrImageInfo['height']) { Asido::height($i1, $FileSourPicSize[1]); if ($this->arrGPic['waterMark']) { Asido::watermark($i1, __WEB_ROOT . "/data/" . $this->arrGPic['waterImage'], $this->arrGPic['waterPos'], ASIDO_WATERMARK_SCALABLE_ENABLED, 0.5); } $i1->save(ASIDO_OVERWRITE_ENABLED); } return $strPhoto; } elseif ($FileSourPicSize[1] == 0) { //设定高=0,则不定高,定宽压缩 if ($FileSourPicSize[0] > 0 && $FileSourPicSize[0] < $arrImageInfo['width']) { Asido::width($i1, $FileSourPicSize[0]); if ($this->arrGPic['waterMark']) { Asido::watermark($i1, __WEB_ROOT . "/data/" . $this->arrGPic['waterImage'], $this->arrGPic['waterPos'], ASIDO_WATERMARK_SCALABLE_ENABLED, 0.5); } $i1->save(ASIDO_OVERWRITE_ENABLED); } return $strPhoto; } elseif (Asido::resize($i1, $FileSourPicSize[0], $FileSourPicSize[1], $this->arrGPic['zoomMode'])) { //定宽,定高压缩 if ($this->arrGPic['waterMark']) { Asido::watermark($i1, __WEB_ROOT . "/data/" . $this->arrGPic['waterImage'], $this->arrGPic['waterPos'], ASIDO_WATERMARK_SCALABLE_ENABLED, 0.5); } $i1->save(ASIDO_OVERWRITE_ENABLED); return $strPhoto; } else { check::AlertExit($strPicName . '文件上传错误!', -1); } } else { if (!empty($FileSourPicSize)) { check::AlertExit('原图的定义格式已经升级,请检查var.inc.php中$arrGPic[FileSourPicSize]的定义!', -1); } } } else { //原图容量<=最大容量设定,就不压缩原图 if ($intFetch) { if (copy($arrFile['tmp_name'], $strPicName)) { return $strPhoto; } else { echo $strPicName . '文件上传错误!'; exit; } } else { if (move_uploaded_file($arrFile['tmp_name'], $strPicName)) { return $strPhoto; } else { check::AlertExit($strPicName . '文件上传错误!', -1); } } } }
public function uploadImgFile($uploaddir, $file) { $UploadRes = array(); $UploadRes['error'] = false; if ($file['type'] != 'image/jpeg' && $file['type'] != 'image/gif' && $file['type'] != 'image/png') { $UploadRes['error'] = true; $UploadRes['error_message'] = "Принимаются только форматы GIF, JPEG, PNG. "; return $UploadRes; } $sName = $this->makeNormalName($file['name']); $this->getUploadFileName($uploaddir, $sName); // get a free file name, to not replace other image $sName = $this->_sTmp; $uploadfile = $uploaddir . $sName; if (move_uploaded_file($file['tmp_name'], $uploadfile)) { $asido = new Asido(); $asido->Driver('gd'); $im = $asido->Image($uploadfile, $uploadfile); $asido->Fit($im, 90, 90); $im->Save(ASIDO_OVERWRITE_ENABLED); $UploadRes['file_name'] = $sName; return $UploadRes; } else { $UploadRes['error'] = true; $UploadRes['error_message'] = "Проблема при загрузке файла на сервер. Обратитесь к администратору."; return $UploadRes; } }
*/ ///////////////////////////////////////////////////////////////////////////// /** * Include the main Asido class */ include './../../class.asido.php'; /** * Set the correct driver: this depends on your local environment */ Asido::Driver('gd'); /** * Create an Asido_Image object and provide the name of the source * image, and the name with which you want to save the file */ $i1 = Asido::Image('example.png', 'result_04_1.png'); $i2 = Asido::Image('example.png', 'result_04_2.png'); /** * Resize the image by fitting it inside the 800x800 frame: in * fact it will not be resized because it is smaller */ Asido::Fit($i1, 800, 800); /** * Resize the image by fitting it inside the 400x400 frame: the image * will do be resized by making it fit inside the 400x400 "mold" */ Asido::Fit($i2, 400, 400); /** * Save the result */ $i1->Save(ASIDO_OVERWRITE_ENABLED); $i2->Save(ASIDO_OVERWRITE_ENABLED);
* "white" is used to fill the blank areas. This is very handy when you want all * the resulting images to fit inside some frame without stretching them if the * proportions of the image and the frame do not match * * @filesource * @package Asido.Examples * @subpackage Asido.Examples.Resize */ ///////////////////////////////////////////////////////////////////////////// /** * Include the main Asido class */ include './../../class.asido.php'; /** * Set the correct driver: this depends on your local environment */ Asido::Driver('gd'); /** * Create an Asido_Image object and provide the name of the source * image, and the name with which you want to save the file */ $i1 = Asido::Image('example.png', 'result_05.png'); /** * Resize the image by putting it inside a square frame (300x300) with `rgb(177,77,37)` as background. */ Asido::Frame($i1, 300, 300, Asido::Color(39, 107, 20)); /** * Save the result */ $i1->Save(ASIDO_OVERWRITE_ENABLED); /////////////////////////////////////////////////////////////////////////////