本文整理匯總了PHP中image::water方法的典型用法代碼示例。如果您正苦於以下問題:PHP image::water方法的具體用法?PHP image::water怎麽用?PHP image::water使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類image
的用法示例。
在下文中一共展示了image::water方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: pathinfo
}
$field = $uploadFile[0]['path'];
//上傳成功文件物理路徑
$info = pathinfo($field);
$fileData = array();
$fileData[0]['path'] = $field;
//上傳後的大圖
$fileData[0]['url'] = __ROOT__ . '/' . $field;
//上傳後的大圖URL
$json = array();
$json['state'] = $state;
$json['fid'] = md5($field);
if (getimagesize($field)) {
//圖片裁切處理
$img = new image();
$img->water($field);
$json['thumb']['file'] = __ROOT__ . '/' . $field;
$json['thumb']['w'] = $display_width;
$json['thumb']['h'] = $display_height;
}
if ($imagesize && getimagesize($field)) {
//圖片裁切處理
$n = 1;
for ($i = 0; $i < count($size); $i += 2) {
$toFile = $info['filename'] . $n . '.' . $info['extension'];
$img->thumb($field, $toFile, '', $size[$i], $size[$i + 1], $thumb_type);
$fileData[$n]['path'] = $info['dirname'] . '/' . $toFile;
$n++;
}
}
$json['file'] = $fileData;
示例2: save
/**
* 儲存文件
* @param string $file 儲存的文件
* @return boolean
*/
private function save($file)
{
$is_img = 0;
$uploadFileName = mt_rand(1, 9999) . time() . "." . $file['ext'];
$filePath = $this->path . $uploadFileName;
if (in_array(strtolower($file['ext']), array("jpeg", "jpg", "bmp", "gif", "png")) && getimagesize($file['tmp_name'])) {
$imgDir = C("UPLOAD_IMG_DIR") ? C("UPLOAD_IMG_DIR") . "/" : "";
$filePath = $this->path . $imgDir . $uploadFileName;
if (!$this->checkDir($this->path . $imgDir)) {
$this->error = '圖片上傳目錄創建失敗或不可寫';
return false;
}
$is_img = 1;
}
if (!move_uploaded_file($file['tmp_name'], $filePath)) {
$this->error('移動臨時文件失敗');
return false;
}
if (!$is_img) {
$filePath = ltrim(str_replace(ROOT_PATH, '', $filePath), '/');
$arr = array("path" => $filePath, 'fieldname' => $file['fieldname'], 'image' => 0);
} else {
//處理圖像類型文件
$img = new image();
$imgInfo = getimagesize($filePath);
//對原圖進行縮放
if (C("UPLOAD_IMG_RESIZE_ON") && ($imgInfo[0] > C("UPLOAD_IMG_MAX_WIDTH") || $imgInfo[1] > C("UPLOAD_IMG_MAX_HEIGHT"))) {
$img->thumb($filePath, $uploadFileName, C("UPLOAD_IMG_MAX_WIDTH"), C("UPLOAD_IMG_MAX_HEIGHT"), 5, $this->path);
}
//生成縮略圖
if ($this->thumbOn) {
$args = array();
if (empty($this->thumb)) {
array_unshift($args, $filePath);
} else {
array_unshift($args, $filePath, "", "");
$args = array_merge($args, $this->thumb);
}
$thumbFile = call_user_func_array(array($img, "thumb"), $args);
}
//加水印
if ($this->waterMarkOn) {
$img->water($filePath);
}
$filePath = trim(str_replace(ROOT_PATH, '', $filePath), '/');
if ($this->thumbOn) {
$thumbFile = trim(str_replace(ROOT_PATH, '', $thumbFile), '/');
$arr = array("path" => $filePath, "thumb" => $thumbFile, 'fieldname' => $file['fieldname'], 'image' => 1);
} else {
$arr = array("path" => $filePath, 'fieldname' => $file['fieldname'], 'image' => 1);
}
}
$arr['path'] = preg_replace('@\\./@', '', $arr['path']);
//上傳時間
$arr['uptime'] = time();
$info = pathinfo($filePath);
$arr['fieldname'] = $file['fieldname'];
$arr['basename'] = $info['basename'];
$arr['filename'] = $info['filename'];
$arr['size'] = $file['size'];
$arr['ext'] = $file['ext'];
$dir = str_ireplace("\\", "/", dirname($arr['path']));
$arr['dir'] = substr($dir, "-1") == "/" ? $dir : $dir . "/";
return $arr;
}
示例3: save
/**
* 儲存文件
* @param string $file 儲存的文件
* @return boolean
*/
private function save($file)
{
$is_img = 0;
$uploadFileName = mt_rand(1, 9999) . time() . "." . $file['ext'];
$filePath = $this->path . $uploadFileName;
if (in_array(strtolower($file ['ext']), array("jpeg", "jpg", "bmp", "gif", "png")) && getimagesize($file ['tmp_name'])) {
$imgDir = C("UPLOAD_IMG_DIR") ? C("UPLOAD_IMG_DIR") . "/" : "";
$filePath = $this->path . $imgDir . $uploadFileName;
if (!$this->checkDir($this->path . $imgDir)) {
$this->error = L("upload_save_error1");
return false;
}
$is_img = 1;
}
if (!move_uploaded_file($file ['tmp_name'], $filePath)) {
$this->error(L("upload_save_error2"));
return false;
}
if (!$is_img) {
$filePath = ltrim(str_replace(PATH_ROOT, '', $filePath), '/');
return array("path" => $filePath, 'fieldname' => $file['fieldname']);
}
//處理圖像類型文件
$img = new image ();
//對原圖進行縮放
if (C("UPLOAD_IMG_RESIZE_ON")) {
$img->thumb($filePath, $uploadFileName, '', C("UPLOAD_IMG_MAX_WIDTH"), C("UPLOAD_IMG_MAX_HEIGHT"), 5);
}
//生成縮略圖
if ($this->thumbOn) {
$args = array();
if (empty($this->thumb)) {
array_unshift($args, $filePath);
} else {
array_unshift($args, $filePath, "", "");
$args = array_merge($args, $this->thumb);
}
$thumbFile = call_user_func_array(array($img, "thumb"), $args);
}
//加水印
if ($this->waterMarkOn) {
$img->water($filePath);
}
$filePath = ltrim(str_replace(ROOT_PATH, '', $filePath), '/');
$arr = array();
if ($this->thumbOn) {
$thumbFile = ltrim(str_replace(PATH_ROOT, '', $thumbFile), '/');
$arr = array("path" => $filePath, "thumb" => $thumbFile);
} else {
$arr = array("path" => $filePath);
}
return array_merge($arr, $file);
}