本文整理汇总了PHP中image::zfResize方法的典型用法代码示例。如果您正苦于以下问题:PHP image::zfResize方法的具体用法?PHP image::zfResize怎么用?PHP image::zfResize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类image
的用法示例。
在下文中一共展示了image::zfResize方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action_picUpload
public function action_picUpload()
{
if (!isset($_SESSION['canupload'])) {
exit;
}
$error = 0;
if (isset($_FILES['thumb'])) {
$photo = $_FILES['thumb'];
if (substr($photo['type'], 0, 5) == 'image') {
switch ($photo['type']) {
case 'image/jpeg':
case 'image/jpg':
case 'image/pjpeg':
$ext = '.jpg';
break;
case 'image/gif':
$ext = '.gif';
break;
case 'image/png':
case 'image/x-png':
$ext = '.png';
break;
default:
$error = -1;
break;
}
if ($error == 0) {
$time = SYS_TIME;
$year = date('Y', $time);
$month = date('m', $time);
$day = date('d', $time);
$pathInfo = upFileFolders($time);
$dstFolder = $pathInfo['path'];
$dstFile = ABS_PATH . 'upload' . DIRECTORY_SEPARATOR . 'temp' . $ext;
//the size of file uploaded must under 1M
if ($photo['size'] > 2000000) {
$error = -2;
return $error;
}
} else {
return $error;
}
//if no error
if ($error == 0) {
$rand = randStr(4);
//delete primary files
if (file_exists($dstFolder . $time . $rand . $ext)) {
unlink($dstFolder . $time . $rand . $ext);
}
if ($ext != '.gif') {
//save the temporary file
move_uploaded_file($photo['tmp_name'], $dstFile);
$imgInfo = getimagesize($dstFile);
//generate new files
$imageWidth = intval($_POST['width']) != 0 ? intval($_POST['width']) : $imgInfo[0];
$imageHeight = intval($_POST['height']) != 0 ? intval($_POST['height']) : $imgInfo[1];
bpBase::loadSysClass('image');
image::zfResize($dstFile, $dstFolder . $time . $rand . '.jpg', $imageWidth, $imageHeight, 1 | 4, 2);
$ext = '.jpg';
//
} else {
move_uploaded_file($photo['tmp_name'], $dstFolder . $time . $rand . '.gif');
}
if (isset($_POST['channelid'])) {
//内容缩略图
$channelObj = bpBase::loadAppClass('channelObj', 'channel');
$thisChannel = $channelObj->getChannelByID($_POST['channelid']);
$articleObj = bpBase::loadAppClass('articleObj', 'article');
$articleObj->setOtherThumb($thisChannel, $dstFile, $dstFolder, $time . $rand, 'jpg');
}
if ($ext != '.gif') {
@unlink($dstFile);
}
$location = MAIN_URL_ROOT . '/upload/images/' . $year . '/' . $month . '/' . $day . '/' . $time . $rand . $ext;
$error = 0;
}
} else {
$error = -1;
}
} else {
$error = -1;
}
if ($error == 0) {
echo $location;
} else {
$errors = array(-1 => '你上传的不是图片', -2 => '文件不能超过2M', -3 => '图片地址不正确');
echo $errors[intval($error)];
}
}
示例2: autophoto201307023_b
public function autophoto201307023_b()
{
$taskName = 'autophoto201307023_b';
$thisTask = $this->update_log_db->get_one(array('file' => $taskName));
$this->_executedCheck($taskName, $thisTask);
//
$autoclassification_db = bpBase::loadModel('autoclassification_model');
$autos = $autoclassification_db->select('logo!=\'\' AND logo IS NOT NULL', '*', '', 'id ASC');
$count = count($autos);
$i = intval($_GET['i']);
//
if ($i < $count) {
$step = 5;
for ($j = 0; $j < $step; $j++) {
$num = $i + $j;
//
$logoPathDir = ABS_PATH . 'autoPhotos' . DIRECTORY_SEPARATOR . 'logo' . DIRECTORY_SEPARATOR . $autos[$num]['id'] . DIRECTORY_SEPARATOR;
bpBase::loadSysClass('image');
@($imgInfo = getimagesize($logoPathDir . 'logo_s.jpg'));
if ($imgInfo[0] > 100) {
@copy($logoPathDir . 'logo_s.jpg', $logoPathDir . 'logo_s.jpg.bak');
image::zfResize($logoPathDir . 'logo_s.jpg', $logoPathDir . 'logo_s.jpg', 80, 60, 1, 2, 0, 0, 0);
echo $autos[$num]['id'] . '<br>';
}
}
$i = $i + $step;
showMessage($thisTask['des'] . ':' . $i . '/' . $count, '?m=update&c=updateTask&a=' . $taskName . '&i=' . $i, 0);
} else {
$this->_finishTask($taskName);
}
}
示例3: autoSaveRemoteImage
public function autoSaveRemoteImage($str, $baseURI = '')
{
$str = stripslashes($str);
$watermark = bpBase::loadSysCLass('watermark');
$img_array = array();
//$str = stripslashes($str);
if (get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
preg_match_all('#src="(http://(((?!").)+).(jpg|gif|bmp|png))"#i', $str, $img_array);
$img_array_urls = array_unique($img_array[1]);
$dstFolder = ABS_PATH . 'upload' . DIRECTORY_SEPARATOR . 'images';
@chmod($dstFolder, 0777);
if ($baseURI) {
$img_array_urls = $this->_expandlinks($img_array_urls, $baseURI);
if ($img_array_urls) {
exit;
}
}
if ($img_array_urls) {
$i = 0;
$time = SYS_TIME;
foreach ($img_array_urls as $k => $v) {
if (!strpos($v, $_SERVER['HTTP_HOST'])) {
//不保存本站的
$filenames = explode('.', $v);
$filenamesCount = count($filenames);
//
$year = date('Y', $time);
$month = date('m', $time);
$pathInfo = upFileFolders($time);
$dstFolder = $pathInfo['path'];
$rand = randStr(4);
$filePath = $dstFolder . $time . $rand . '.' . $filenames[$filenamesCount - 1];
//
@httpCopy($v, $filePath, 5);
//自动缩放
$imgInfo = @getimagesize($filePath);
$maxPicWidth = intval(loadConfig('cmsContent', 'maxPicWidth'));
$maxPicWidth = $maxPicWidth < 1 ? 500 : $maxPicWidth;
if ($imgInfo[0] > $maxPicWidth) {
$newWidth = $maxPicWidth;
$newHeight = $imgInfo[1] * $newWidth / $imgInfo[0];
bpBase::loadSysClass('image');
image::zfResize($filePath, $filePath, $newWidth, $newHeight, 1, 2, 0, 0, 1);
}
//
if (file_exists($filePath)) {
$watermark->wm($filePath);
$str = str_replace($v, 'http://' . $_SERVER['HTTP_HOST'] . CMS_DIR_PATH . $pathInfo['url'] . $time . $rand . '.' . $filenames[$filenamesCount - 1], $str);
}
}
$i++;
}
}
return $str;
}
示例4: picUpload
public function picUpload()
{
$result = array();
if (count($_POST)) {
$result['post'] = $_POST;
}
if (count($_FILES)) {
$result['files'] = $_FILES;
}
// Validation
$error = false;
if (!isset($_FILES['Filedata']) || !is_uploaded_file($_FILES['Filedata']['tmp_name'])) {
$error = 'Invalid Upload';
exit;
}
// Processing start
$photo = $_FILES['Filedata'];
$time = SYS_TIME;
$year = date('Y', $time);
$month = date('m', $time);
$day = date('d', $time);
$pathInfo = upFileFolders($time);
$dstFolder = $pathInfo['path'];
$rand = randStr(4);
$dstFile = $dstFolder . $time . $rand . $photo['name'];
//the size of file uploaded must under 1M
if ($photo['size'] > 3000000) {
$error = '图片太大不能超过3M';
exit;
}
//save the temporary file
@move_uploaded_file($photo['tmp_name'], $dstFile);
//
//自动缩放
$imgInfo = @getimagesize($dstFile);
$maxPicWidth = intval(loadConfig('cmsContent', 'maxPicWidth'));
$maxPicWidth = $maxPicWidth < 1 ? 500 : $maxPicWidth;
if ($imgInfo[0] > $maxPicWidth) {
$newWidth = $maxPicWidth;
$newHeight = $imgInfo[1] * $newWidth / $imgInfo[0];
} else {
$newWidth = $imgInfo[0];
$newHeight = $imgInfo[1];
}
bpBase::loadSysClass('image');
bpBase::loadSysClass('watermark');
image::zfResize($dstFile, $dstFolder . $time . $rand . '.jpg', $newWidth, $newHeight, 1, 2, 0, 0, 1);
//delete the temporary file
@unlink($dstFile);
$location = CMS_DIR_PATH . $pathInfo['url'] . $time . $rand . '.jpg';
//
bpBase::loadSysClass('image');
bpBase::loadSysClass('watermark');
$wm = new watermark();
$wm->wm($dstFolder . $time . $rand . '.jpg');
//
$filePath = $location;
//processing end
if ($error) {
$return = array('status' => '0', 'error' => $error);
} else {
$return = array('status' => '1', 'name' => ABS_PATH . $filePath);
// Our processing, we get a hash value from the file
$return['hash'] = '';
// ... and if available, we get image data
if ($imgInfo) {
$return['width'] = $newWidth;
$return['height'] = $newHeight;
$return['mime'] = $imgInfo['mime'];
$return['url'] = $filePath;
$return['randnum'] = rand(0, 999999);
}
}
// Output
if (isset($_REQUEST['response']) && $_REQUEST['response'] == 'xml') {
// header('Content-type: text/xml');
// Really dirty, use DOM and CDATA section!
echo '<response>';
foreach ($return as $key => $value) {
echo "<{$key}><![CDATA[{$value}]]></{$key}>";
}
echo '</response>';
} else {
// header('Content-type: application/json');
echo json_encode($return);
}
}
示例5: _setFirstImageAsThumb
function _setFirstImageAsThumb($thisChannel, $contentStr, $imgNo = 1)
{
$thumbWidht = $thisChannel->thumbwidth;
$thmbHeight = $thisChannel->thumbheight;
if (!$thumbWidht || !$thmbHeight) {
return '';
}
//get image url
$contentStr = stripslashes($contentStr);
@preg_match_all('#src="((((?!").)+).(jpg|bmp))"#i', $contentStr, $img_array);
$img_array_urls = $img_array[1];
if ($img_array_urls) {
$imgNo = abs(intval($imgNo));
$imgNo = $imgNo < 1 ? 1 : $imgNo;
$imgUrl = $img_array_urls[$imgNo - 1];
if (!strpos($imgUrl, 'ttp://')) {
$imgUrl = MAIN_URL_ROOT . $imgUrl;
}
$time = SYS_TIME;
$pathInfo = upFileFolders($time);
$dstFolder = $pathInfo['path'];
$rand = rand(0, 10000);
$tempImgPath = ABS_PATH . 'upload' . DIRECTORY_SEPARATOR . 'temp.jpg';
if (file_exists($tempImgPath)) {
@unlink($tempImgPath);
}
@httpCopy($imgUrl, $tempImgPath);
//new start,带水印的图片加缩略图需要裁切掉水印
if (file_exists(ABS_PATH . 'constant' . DIRECTORY_SEPARATOR . 'watermark.config.php')) {
@(include_once ABS_PATH . 'constant' . DIRECTORY_SEPARATOR . 'watermark.config.php');
if (USE_WATERMARK) {
if (WATERMARK_TYPE != 'text') {
$oImgSize = getimagesize($tempImgPath);
//原图尺寸
//水印尺寸
$watermarkImageAttr = @getimagesize(ABS_PATH . 'editor' . DIRECTORY_SEPARATOR . 'ckfinder' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'watermark' . DIRECTORY_SEPARATOR . 'logo.png');
$width = $oImgSize[0];
$height = $oImgSize[1] - $watermarkImageAttr[1];
//新图高度为原图高度减水印高度
//
$firstImg = imagecreatefromjpeg($tempImgPath);
if (function_exists("imagecreatetruecolor")) {
//GD2.0.1
$dstScaleImg = imagecreatetruecolor($width, $height);
} else {
$dstScaleImg = imagecreate($width, $height);
}
imagecopy($dstScaleImg, $firstImg, 0, 0, 0, 0, $oImgSize[0], $oImgSize[1]);
//裁切
ImageJPEG($dstScaleImg, ABS_PATH . 'upload' . DIRECTORY_SEPARATOR . 'temp.jpg');
//保存图片
imagedestroy($dstScaleImg);
imagedestroy($firstImg);
}
}
}
//new end,裁切水印end
bpBase::loadSysClass('image');
image::zfResize(ABS_PATH . 'upload' . DIRECTORY_SEPARATOR . 'temp.jpg', $dstFolder . $time . $rand . '.jpg', $thumbWidht, $thmbHeight, 1 | 4, 2);
$this->_setThumb($thisChannel, ABS_PATH . 'upload' . DIRECTORY_SEPARATOR . 'temp.jpg', $dstFolder, $time . $rand, 'jpg');
@unlink(ABS_PATH . 'upload' . DIRECTORY_SEPARATOR . 'temp.jpg');
//
$year = date('Y', $time);
$month = date('m', $time);
$day = date('d', $time);
$url = $pathInfo['url'] . $time . $rand . '.jpg';
//
$location = 'http://' . $_SERVER['HTTP_HOST'] . CMS_DIR_PATH . $url;
return $location;
} else {
return '';
}
//
}