/** * @param array $action * @param int $sourceId */ function generateFormImage( $action, $sourceId ) { $translation = ImageTool::getTranslationFromDb( $sourceId, $action['param'], $db ); $source = $translation['source']; $text = $translation['translation']; $imageTool = new ImageTool( $action['identifier'], $source, 'form', true ); $imageTool->generateAndSaveImage( $text ); }
public function getImageWithSize($width, $height) { if ($this->image && file_exists(Yii::app()->params['imagePath'] . $this->image)) { $_image = ImageTool::resize($this->image, $width, $height); } else { $_image = ImageTool::resize('no_image.jpg', $width, $height); } return $_image; }
/** * 上传文件 * @param $file array 文件上传信息 * @return 返回上传信息 错误代码 0:上传成功 ,1:文件太大,超出php.ini的限制,2:文件太大,超出MAX_FILE_SIZE的限制,3:文件没有上传完,4:没有上传文件,6&7:临时文件夹错误 */ public function upload($file) { if ($file['error'] == 0) { if (!in_array($file['type'], $this->allow_types)) { $this->error_info = '文件类型错误!'; return false; } else { if ($file['size'] > $this->max_size) { $this->error_info = '文件太大!'; return false; } else { if (!is_uploaded_file($file['tmp_name'])) { $this->error_info = '文件错误!'; return false; } else { $new_name = uniqid('goods_') . strrchr($file['name'], '.'); $save_path = $this->upload_dir; $subdir_str = date('Ymd'); if (!is_dir($this->upload_dir)) { mkdir($this->upload_dir, true); } if ($this->is_sub) { $subdir_name = $this->upload_dir . $subdir_str . DIRECTORY_SEPARATOR; if (!is_dir($subdir_name)) { mkdir($subdir_name, true); } $save_path = $subdir_name; } move_uploaded_file($file['tmp_name'], $save_path . $new_name); $image_tool = new ImageTool($save_path . $new_name); $thumb_name = $image_tool->makeThumb(100, 100); $image_tool->waterMark(UPLOAD_PATH . 'yimolife.png'); return array(($this->is_sub ? $subdir_str . '/' : '') . $new_name, ($this->is_sub ? $subdir_str . '/' : '') . $thumb_name); } } } } else { $this->error_info = '文件上传失败,可能的原因:文件过大。错误代码100' . $file['error']; return false; } }
public function getImageWithSize($width = 0, $height = 0) { if ($width === 0 || $height === 0) { return Yii::app()->getBaseUrl() . DIRECTORY_SEPARATOR . 'image' . DIRECTORY_SEPARATOR . $this->image; } if ($this->image && file_exists(Yii::app()->params['imagePath'] . $this->image)) { $_image = ImageTool::resize($this->image, $width, $height); } else { $_image = ImageTool::resize('no_image.jpg', $width, $height); } return $_image; }
} /*检验验证码*/ if ($_SESSION['rand'] != $_POST['code']) { $url = 'login.php?pass=reg'; Header("Location: {$url}"); exit; } $data = $user->_autoFill($_POST); // 自动填充 $data = $user->_facade($data); // 自动过滤 $data['nickname'] = '野人'; $data['head_img'] = 'templates/images/default.jpg'; $ori_img = $data['head_img']; //缩略图 if ($ori_img) { $ori_img = ROOT . $ori_img; // 加上绝对路径 $goods_img = dirname($ori_img) . '/small_' . basename($ori_img); if (ImageTool::thumb($ori_img, $goods_img, 93)) { $data['hd_small_img'] = str_replace(ROOT, '', $goods_img); } } if ($user->reg($data)) { $msg = '用户注册成功'; } else { $msg = '用户注册失败'; } // 引入view $url = 'login.php?pass=log'; Header("Location: {$url}");
public function actionImage($image) { $imageTool = new ImageTool(); echo $imageTool->resize(html_entity_decode($image, ENT_QUOTES, 'UTF-8'), 100, 100); }
echo "<script>alert('表单填写错误," . implode('', $goods->getError()) . "');history.back()</script>"; exit; } /** * 上传图片 */ $uptool = new UpTool(); $ori_img = $uptool->up('ori_img'); if ($ori_img) { $data['ori_img'] = $ori_img; /** * 如果上传成功 则生成缩略图 300*400 * 再生成浏览时的小图 160*220 */ $ori_img = ROOT . $ori_img; $goods_image = dirname($ori_img) . '/goods_' . basename($ori_img); if (ImageTool::thumb($ori_img, $goods_image, 300, 400)) { $data['goods_img'] = str_replace(ROOT, '', $goods_image); } $thumb_image = dirname($ori_img) . '/thumb_' . basename($ori_img); if (ImageTool::thumb($ori_img, $thumb_image, 300, 400)) { $data['thumb_img'] = str_replace(ROOT, '', $thumb_image); } } if ($goods->add($data)) { echo "<script>alert('商品添加成功');history.back();</script>"; exit; } else { echo "<script>alert('商品添加失败');history.back();</script>"; exit; }
public function admin_perfil($id) { if ($id != $this->Auth->user('id')) { $this->Session->setFlash('No esta autorizado', 'flash/error'); $this->redirect(array('controller' => 'pages', 'action' => 'display', 'home', 'admin' => true)); } $this->Usuario->id = $id; if (!$this->Usuario->exists($id)) { throw new NotFoundException(__('Invalid usuarios table')); } if ($this->request->is('post') || $this->request->is('put')) { App::import('Vendor', 'ImageTool'); // unset ( $this->request->data ['Usuario'] ['nombre_completo'] ); unset($this->request->data['Usuario']['usuario_login']); unset($this->request->data['Usuario']['borrado']); unset($this->request->data['Usuario']['id_anterior']); unset($this->request->data['Grupo']); if (empty($this->request->data['Usuario']['constrasenia'])) { unset($this->request->data['Usuario']['constrasenia']); } $foto = false; $e = false; if ($this->request->data['Usuario']['imagen']['name'] != '') { $foto = true; // ERRORES $error[0] = "El archivo debe estar en formato JPG."; $error[1] = "La imagen no puede sobrepasar los 2 MB."; $error[2] = "La imagen no pudo ser subida correctamente."; // variables $filename = trim($this->data['Usuario']["imagen"]['name']); $tamano_archivo = $this->data['Usuario']["imagen"]['size']; $tmp_name = $this->data['Usuario']["imagen"]['tmp_name']; // SI EL ARCHIVO NO ES JPG $palabra = preg_quote('.jpg'); if (!eregi($palabra, $filename)) { $this->Session->setFlash($error[0], 'flash/error'); $e = true; } // COMPRUEBA QUE EL JPG SEA MENOR DE 2 MB... if ($tamano_archivo > 2048000) { $this->Session->setFlash($error[1], 'flash/error'); $e = true; } } if ($e == false) { if ($this->Usuario->save($this->request->data)) { // Cargo de nuevo el usuario porque sino tengo campos con unset $options = array('conditions' => array('Usuario.' . $this->Usuario->primaryKey => $id)); $this->request->data = $this->Usuario->find('first', $options); if ($foto == true) { $usuario_id = $this->Auth->user('id'); // Recupero la ID del animal $uploaddir = "perfiles/"; // Directorio para guardar la imagen del animal $filename = $usuario_id . "_" . md5($usuario_id) . ".jpg"; $uploadfile = $uploaddir . $filename; // Direccion del archivo subido $status = ImageTool::resize(array('input' => $tmp_name, 'output' => $uploadfile, 'width' => 50, 'height' => 50, 'quality' => 50)); // SI SE SUBE EL ARCHIVO if ($status) { // Si se sube correctamente devuelve verdadero chmod($uploadfile, 0644); $this->Session->setFlash(__('El registro fue guardado correctamente.'), 'flash/success'); // $this->redirect(array('action' => 'index')); } else { // SI HAY ALGUN ERROR BORRO EL ARCHIVO @unlink($uploadfile); $this->Session->setFlash(__('No se pudo editar el registro. Por favor, vuelva a intentarlo.'), 'flash/error'); // $this->redirect(array('action' => 'index')); } } else { $this->Session->setFlash(__('El registro fue guardado correctamente.'), 'flash/success'); // $this->redirect(array('action' => 'index')); } } else { $this->Session->setFlash(__('No se pudo editar el registro. Por favor, vuelva a intentarlo.'), 'flash/error'); } } } else { $options = array('conditions' => array('Usuario.' . $this->Usuario->primaryKey => $id)); $this->request->data = $this->Usuario->find('first', $options); } }
$color = imagecolorallocate($dim, 255, 255, 255); //填充颜色 imagefill($dim, 0, 0, $color); //创建要缩略的图像 $dfunc = 'imagecreatefrom' . $sinfo['ext']; $sim = $dfunc($src); //上下或者两边留白设置 $dst_x = (int) ($width - (int) $sinfo['width'] * $calc) / 2; $dst_y = (int) ($height - (int) $sinfo['height'] * $calc) / 2; //缩略 imagecopyresampled($dim, $sim, $dst_x, $dst_y, 0, 0, $sinfo['width'] * $calc, $sinfo['height'] * $calc, $sinfo['width'], $sinfo['height']); //保存图片如果没有传保存地址则覆盖原图 if (!$save) { $save = $src; } $createfunc = 'image' . $sinfo['ext']; $createfunc($dim, $save); imagedestroy($dim); imagedestroy($sim); return true; } } // $dst = './1.png'; // $water = './1.jpg'; // //[加水印的位置:1=左上;2=上中;3=右上;4=左中;5=中中;6=右中;7=左下;8=中下;9=右下] // ImageTool::water($dst, $water,2); $src = './2222.jpg'; ImageTool::thumb($src, './thumb4.jpg', 200, 200); ImageTool::thumb($src, './thumb5.jpg', 300, 200); ImageTool::thumb($src, './thumb6.jpg', 200, 300);
/** * 生成缩略图并打水印 * @param string $file 文件全名 * @return string 缩略图名字 */ function makeThumb($file) { $image_tool = new ImageTool($file); $new_name = $image_tool->makeThumb(300, 300); $image_tool->waterMark('./upload/cklogo.png'); return $new_name; }
<?php define('ACC', true); require './include/init.php'; /*验证码*/ $vcode = new ImageTool(); $vimg = $vcode->captcha(110, 44);
exit; } // 2012年12月4日 上传图片 $uptool = new UpTool(); $ori_img = $uptool->up('ori_img'); if ($ori_img) { $data['ori_img'] = $ori_img; } // 如果$ori_img上传成功,再次生成中等大小缩略图 300*400 // 根据原始地址 定 中等图的地址 // 例:aa.jpeg --> goods_aa.jpeg if ($ori_img) { $ori_img = ROOT . $ori_img; // 加上绝对路径 $goods_img = dirname($ori_img) . '/goods_' . basename($ori_img); if (ImageTool::thumb($ori_img, $goods_img, 300, 400)) { $data['goods_img'] = str_replace(ROOT, '', $goods_img); } // 再次生成浏览时用缩略图 160*220 // 定好缩略图的地址 // aa.jpeg --> thumb_aa.jpeg $thumb_img = dirname($ori_img) . '/thumb_' . basename($ori_img); if (ImageTool::thumb($ori_img, $thumb_img, 160, 220)) { $data['thumb_img'] = str_replace(ROOT, '', $thumb_img); } } if ($goods->add($data)) { echo '商品发布成功'; } else { echo '商品发布失败'; }
$clusterIdentifier = ClusterTool::clusterIdentifier(); $type = $Params['Type']; $source = $Params['TranslationSource']; $forceRegeneration = false; if ( isset( $Params['ForceRegeneration'] ) ) { $forceRegeneration = true; } $context = ImageTool::determineContextFromType( $type ); if ( !$context ) { eZDebug::writeError( "Couldn't determine translation context from given type." ); header( 'HTTP/1.0 404 Not Found' ); eZExecution::cleanExit(); } if ( !$source ) { eZDebug::writeError( "No translation source specified." ); header( 'HTTP/1.0 404 Not Found' ); eZExecution::cleanExit(); } $imageTool = new ImageTool( $clusterIdentifier, $source, 'form', $forceRegeneration ); $imageFile = $imageTool->getFormImage(); header( 'Content-Type: image/png' ); header( 'Content-Length: ' . $imageTool->fileUtils->size() ); echo $imageFile; eZExecution::cleanExit();
$word = new WordModel(); $data = array(); $data = $word->_facade($_POST); // 自动过滤 $data = $word->_autoFill($data); // 自动填充 $data['user_id'] = $_SESSION['id']; $ori_img = $_POST['source_img']; //缩略图 if ($ori_img) { $ori_img = ROOT . $ori_img; // 加上绝对路径 $goods_img = dirname($ori_img) . '/small_' . basename($ori_img); if (ImageTool::thumb($ori_img, $goods_img, 230)) { $data['small_img'] = str_replace(ROOT, '', $goods_img); } // 再次生成浏览时用缩略图 160*220 // 定好缩略图的地址 // aa.jpeg --> thumb_aa.jpeg $thumb_img = dirname($ori_img) . '/center_' . basename($ori_img); if (ImageTool::thumb($ori_img, $thumb_img, 316)) { $data['center_img'] = str_replace(ROOT, '', $thumb_img); } } if ($word->add($data)) { $url = 'index.php'; Header("Location: {$url}"); } else { $url = 'login.php?status=fial'; Header("Location: {$url}"); }