本文整理汇总了PHP中resize函数的典型用法代码示例。如果您正苦于以下问题:PHP resize函数的具体用法?PHP resize怎么用?PHP resize使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了resize函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: editdata
function editdata()
{
require '../include/config.php';
$id = $_POST['id'];
$name = $_POST['txtname'];
$code = $_POST['txtcode'];
$posision = $_POST['txtposision'];
$line = $_POST['txtline'];
$link = $_POST['txtlink'];
$datestart = $_POST['datestart'];
$dateend = $_POST['dateend'];
$status = $_POST['status'];
$file = $_FILES['fle']['name'];
$file_tmp = $_FILES['fle']['tmp_name'];
$update = "UPDATE banner_ads SET baname = '{$name}',\r\n \t\t\t\t\t\t\t\t bacode = '{$code}',\r\n \t\t\t\t\t\t\t\t baposition = '{$posision}',\r\n \t\t\t\t\t\t\t\t baline = '{$line}',\r\n \t\t\t\t\t\t\t\t balink = '{$link}',\r\n \t\t\t\t\t\t\t\t datestart = '{$datestart}',\r\n \t\t\t\t\t\t\t\t dateend = '{$dateend}'";
if ($file != "") {
//check_size($file_tmp);
$imgname = md5($file);
$dot = substr($file, -3, 3);
$pic_name = md5($id) . '_' . $imgname . "-" . time() . "." . $dot;
resize($file_tmp, $pic_name, 300, "../../images/banner/ads/tmp/");
copy($file_tmp, "../../images/banner/ads/{$pic_name}");
$update .= ",baimg = '{$pic_name}'";
}
$update .= ",status = '{$status}' where baid = '{$id}' ";
$dbCon->query($update) or die($dbCon->error);
$dbCon->close();
//echo $update;
header("Location: ../banner/bannerads");
exit;
}
示例2: validateAndSave
function validateAndSave($file)
{
$result = array();
if (!preg_match('/^image\\//', $file['type']) || !preg_match('/\\.(jpe?g|JPE?G|GIF|gif|PNG|png)$/', $file['name']) || getimagesize($file['tmp_name']) === FALSE) {
//then there is an error
$result['status'] = 'ERR';
$result['message'] = 'Неверный формат файла!';
} else {
if ($file['size'] > 3145728) {
//if size is larger than what we expect
$result['status'] = 'ERR';
$result['message'] = 'Пожалуйста, выберите файл меньшего размера!';
} else {
if ($file['error'] != 0 || !is_uploaded_file($file['tmp_name'])) {
//if there is an unknown error or temporary uploaded file is not what we thought it was
$result['status'] = 'ERR';
$result['message'] = 'Неизвестная ошибка!';
} else {
//save file inside current directory using a safer version of its name
$info = @getimagesize($file['tmp_name']);
$new_mame = uniqid() . "." . basename($info['mime']);
$save_path = 'upload/img_gallery/' . preg_replace('/[^\\w\\.\\- ]/', '', $new_mame);
//thumbnail name is like filename-thumb.jpg
$thumb_path = preg_replace('/\\.(.+)$/', '', $save_path) . '-thumb.jpg';
if (!move_uploaded_file($file['tmp_name'], $save_path) or !resize($save_path, $thumb_path, 150)) {
$result['status'] = 'ERR';
$result['message'] = 'Невозможно сохранить файл!';
} else {
require "templates/db_con.php";
// require("templates/sait_con.php");
//---------------------- пишем в базу
//print_r($_POST);
$thumb_name = preg_replace('/\\.(.+)$/', '', $new_mame) . '-thumb.jpg';
$STH = $dbh->prepare('INSERT INTO `gallery_detail` (
`full_name`,
`short_name`,
`gallery_id`,
`user_id`,
`active`) VALUES (
"' . $new_mame . '",
"' . $thumb_name . '",
"' . $_POST['form-fid'] . '",
"' . $_SESSION['user_id'] . '",
"Y");');
$STH->execute();
$id = $dbh->lastInsertId();
//------------------------
//everything seems OK
$result['status'] = 'OK';
$result['message'] = 'Аватар успешно изменен!';
//include new thumbnails `url` in our result and send to browser
$result['url'] = $thumb_path;
$result['url_full'] = $save_path;
$result['id'] = $id;
}
}
}
}
return $result;
}
示例3: resize
function resize(&$new_width, &$new_height, $original_width, $original_height)
{
$xscale = $new_width / $original_width;
$yscale = $new_height / $original_height;
if ($new_width <= $original_width and $new_height <= $original_height and $xscale == $yscale) {
return;
}
if ($new_width and !$new_height) {
return $new_height = $new_width / $original_width * $original_height;
} elseif (!$new_width and $new_height) {
return $new_width = $new_height / $original_height * $original_width;
}
if ($xscale != $yscale) {
if ($original_width * $yscale <= $new_width) {
$new_width = $original_width * $yscale;
}
if ($original_height * $xscale <= $new_height) {
$new_height = $original_height * $xscale;
}
}
$xscale = $new_width / $original_width;
$yscale = $new_height / $original_height;
if (round($xscale, 3) == round($yscale, 3)) {
return;
}
resize($new_width, $new_height, $original_width, $original_height);
}
示例4: doImage
function doImage($source, $width, $height, $timestamp = true, $name)
{
$origImage = getImage($source, $width, $height);
if (is_null($origImage)) {
die("Rendering Error");
}
$image = resize($origImage, $width, $height);
$thumb = resize($origImage, 100, 75);
if ($timestamp) {
$image = addTimeStamp($image);
}
$compression = 75;
$filepath = "screenshots/";
$filename = $filepath . $name . "_" . time() . ".jpg";
$filename_thumb = $filepath . $name . "_" . time() . "_thumb.jpg";
//main image
imagejpeg($image, $filename, $compression);
chmod($filename, 0600);
imagedestroy($image);
//thumb image
imagejpeg($thumb, $filename_thumb, $compression);
chmod($filename_thumb, 0600);
imagedestroy($thumb);
echo "OK";
}
示例5: create
public function create()
{
$imgs = [];
$path = 'uploads/img/' . date('Y/m/d/');
if (!is_dir($path)) {
mkdir($path, 0777, true);
}
foreach ($_POST['imgurls'] as $imgurl) {
$file = parse_url($imgurl)['path'];
$file = substr($file, 1);
$md5 = md5_file($file);
$ext = '.' . substr($file, -3);
$small = $path . $md5 . '_s' . $ext;
$big = $path . $md5 . $ext;
if (!file_exists($big)) {
copy($file, $big);
}
if (!file_exists($small)) {
resize($file, 0, 170, $small);
}
$imgs[] = ['small' => $small, 'big' => $big];
}
$photo = new Photo();
$photo->userid = $this->user['userid'];
$photo->saying = $_POST['saying'];
$photo->subject_id = $_POST['movie_id'];
$photo->imgs = $imgs;
$photo->save();
return [];
}
示例6: getOneMap
/**
* Сачати картинку за вказану дату
* @param $timestamp
*
*/
function getOneMap($timestamp)
{
ini_set("allow_url_fopen", 1);
$dYear = date('Y', $timestamp);
$dMonth = date('m', $timestamp);
$dDay = date('d', $timestamp);
// http://mediarnbo.org/wp-content/uploads/2014/08/13-08.jpg
// http://mediarnbo.org/wp-content/uploads/2014/08/15-08.jpg
$url = SOURCE_LINK . $dYear . '/' . $dMonth . '/';
$imgName = $dDay . '-' . $dMonth . '.jpg';
$handle = fopen(ERRORS_FILE, 'w');
// file to write errors
$source = getFilenameOnDiskBig($timestamp);
$target = getFilenameOnDiskSml($timestamp);
try {
copy($url . $imgName, PATH_SAVE . $source);
} catch (Exception $e) {
$s = "Not exist: " . $url . $imgName . "\n";
fwrite($handle, $s);
}
// wln($url.$imgName);
sleep(1);
if (file_exists(PATH_SAVE . $source)) {
resize(SML_IMG_WIDTH, PATH_SAVE . $target, PATH_SAVE . $source);
echo '<img src="' . HOST . 'img/photos/' . $target . '"/>';
} else {
print_r("Not exist: " . $url . $imgName . "\n");
}
fclose($handle);
}
示例7: editdata
function editdata()
{
require '../include/config.php';
$id = $_POST['id'];
$name = $_POST['txtname'];
$detail = $_POST['txtdetail'];
$userid = $_POST['userid'];
$status = $_POST['status'];
$file = $_FILES['fle']['name'];
$file_tmp = $_FILES['fle']['tmp_name'];
$update = "UPDATE post SET postname = '{$name}',\r\n \t\t\t\t\t\t\tpostdetail = '{$detail}',\r\n \t\t\t\t\t\t\tuser_id = '{$userid}',\r\n \t\t\t\t\t\t\tstatus = '{$status}'";
if ($file != "") {
//check_size($file_tmp);
$imgname = md5($file);
$dot = substr($file, -3, 3);
$pic_name = $imgname . "-" . time() . "." . $dot;
resize($file_tmp, $pic_name, 250, "../../images/post/tmp/");
copy($file_tmp, "../../images/post/{$pic_name}");
$update .= ",postimg = '{$pic_name}'";
}
$update .= " where postid = '{$id}' ";
$dbCon->query($update) or die($dbCon->error);
$dbCon->close();
//echo $update;
header("Location: ../posts");
exit;
}
示例8: image_upload_file
function image_upload_file($target_path, $thumbnail_path, $name, $file_basename, $type, $size, $tmp_name, $isMakeThum)
{
//$file_basename = substr($name, 0, strripos($name, '.')); // get file extention
$file_ext = strtolower(substr($name, strripos($name, '.')));
// get file name
$allowed_file_types = array('.jpg', '.png', '.rtf', '.pdf');
write_log("Upload: " . $name, UPLOAD_LOG);
write_log("Type: " . $type, UPLOAD_LOG);
write_log("Size:" . $size / 1024 . " Kb", UPLOAD_LOG);
write_log("Stored in: " . $tmp_name, UPLOAD_LOG);
write_log("file_ext : " . $file_ext, UPLOAD_LOG);
//if (in_array($file_ext,$allowed_file_types) && ($size < 20000000))
if (in_array($file_ext, $allowed_file_types) && $size < MAX_FILE_SIZE) {
// Rename file
//$target_path = "uploads/";
$newfilename = md5($file_basename) . $file_ext;
write_log("newfilename : " . $newfilename);
if (file_exists($target_path . $newfilename)) {
// file already exists error
$message = "You have already uploaded this file.";
$ret = array('file' => $newfilename, 'status' => UploadMessage::ERR_EXIST_FILE, 'message' => $message);
write_log($message, UPLOAD_LOG);
} else {
move_uploaded_file($tmp_name, $target_path . $newfilename);
$ret = UploadMessage::UPLOAD_OK;
$message = "File uploaded successfully.";
$ret = array('file' => $newfilename, 'status' => UploadMessage::UPLOAD_OK, 'message' => $message);
write_log($message, UPLOAD_LOG);
write_log($ret, UPLOAD_LOG);
//make thumbnail image
if ($isMakeThum) {
$ret2 = resize($target_path . $newfilename, $thumbnail_path . $newfilename, 100, 100);
}
}
} elseif (empty($file_basename)) {
// file selection error
$message = "Please select a file to upload.";
$ret = array('file' => $newfilename, 'status' => UploadMessage::ERR_EMPTY_FILE_NAME, 'message' => $message);
write_log("newfilename : " . $newfilename, UPLOAD_LOG);
} elseif ($size > MAX_FILE_SIZE) {
// file size error
$message = "The file you are trying to upload is too large.";
$ret = array('file' => $newfilename, 'status' => UploadMessage::ERR_LARGE_FILE, 'message' => $message);
write_log($message, UPLOAD_LOG);
} else {
// file type error
$message = "Only these file typs are allowed for upload: " . implode(', ', $allowed_file_types);
write_log($message, UPLOAD_LOG);
$ret = array('file' => $newfilename, 'status' => UploadMessage::ERR_FILE_TYPE, 'message' => $message);
unlink($tmp_name);
}
return $ret;
}
示例9: validateAndSave
function validateAndSave($file)
{
$result = array();
if (!preg_match('/^image\\//', $file['type']) || !preg_match('/\\.(jpe?g|gif|png|JPE?G|GIF|PNG)$/', $file['name']) || getimagesize($file['tmp_name']) === FALSE) {
//then there is an error
$result['status'] = 'ERR';
$result['message'] = 'Неверный формат файла!';
} else {
if ($file['size'] > 3145728) {
//if size is larger than what we expect
$result['status'] = 'ERR';
$result['message'] = 'Пожалуйста, выберите файл меньшего размера!';
} else {
if ($file['error'] != 0 || !is_uploaded_file($file['tmp_name'])) {
//if there is an unknown error or temporary uploaded file is not what we thought it was
$result['status'] = 'ERR';
$result['message'] = 'Неизвестная ошибка!';
} else {
//save file inside current directory using a safer version of its name
$info = @getimagesize($file['tmp_name']);
$new_mame = uniqid() . "." . basename($info['mime']);
$save_path = 'upload/img_dish/' . preg_replace('/[^\\w\\.\\- ]/', '', $new_mame);
//thumbnail name is like filename-thumb.jpg
$thumb_path = preg_replace('/\\.(.+)$/', '', $save_path) . '-thumb.jpg';
if (!move_uploaded_file($file['tmp_name'], $save_path) or !resize($save_path, $thumb_path, 220)) {
$result['status'] = 'ERR';
$result['message'] = 'Не удалось сохранить файл!';
} else {
//everything seems OK
$result['status'] = 'OK';
$result['message'] = 'Файл изменен!';
//require("templates/db_con.php");
//require("templates/sait_con.php");
//---------------------- пишем в базу
//print_r($_POST['form-fid']);
$thumb_name = preg_replace('/\\.(.+)$/', '', $new_mame) . '-thumb.jpg';
//$STH=$dbh->prepare('UPDATE `services_products` set `photo`="'.$new_mame.'", `photo_thumb`="'.$thumb_name.'" WHERE id="'.$_POST['form-fid'].'";');
//$STH->execute();
$result['url'] = $thumb_path;
$result['photo'] = $new_mame;
$result['photo_thumb'] = $thumb_name;
}
}
}
}
return $result;
}
示例10: resize
function resize(&$crop_x, &$crop_y, &$new_width, &$new_height, $original_width, $original_height)
{
$xscale = $new_width / $original_width;
$yscale = $new_height / $original_height;
if ($new_width <= $original_width and $new_height <= $original_height and $xscale == $yscale) {
return;
}
if (isset($_GET['square'])) {
if ($new_width === 0) {
$new_width = $new_height;
}
if ($new_height === 0) {
$new_height = $new_width;
}
if ($original_width > $original_height) {
# portrait
$crop_x = ceil(($original_width - $original_height) / 2);
} else {
if ($original_height > $original_width) {
# landscape
$crop_y = ceil(($original_height - $original_width) / 2);
}
}
return;
} else {
if ($new_width and !$new_height) {
return $new_height = $new_width / $original_width * $original_height;
} elseif (!$new_width and $new_height) {
return $new_width = $new_height / $original_height * $original_width;
}
if ($xscale != $yscale) {
if ($original_width * $yscale <= $new_width) {
$new_width = $original_width * $yscale;
}
if ($original_height * $xscale <= $new_height) {
$new_height = $original_height * $xscale;
}
}
$xscale = $new_width / $original_width;
$yscale = $new_height / $original_height;
if (round($xscale, 3) == round($yscale, 3)) {
return;
}
resize($crop_x, $crop_y, $new_width, $new_height, $original_width, $original_height);
}
}
示例11: doImage
function doImage($source, $width, $height, $timestamp = true)
{
$image = getImage($source, $width, $height);
if (is_null($image)) {
die("Rendering Error");
}
//no cache
header("Cache-Control: no-cache, must-revalidate");
// HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
// Date in the past
header('Content-Type: image/jpeg');
$image = resize($image, $width, $height);
if ($timestamp) {
$image = addTimeStamp($image);
}
imagejpeg($image);
imagedestroy($image);
}
示例12: compare
function compare($file1, $file2)
{
global $config;
$file1 = escapeshellcmd($config['destination'] . $file1);
$file2 = escapeshellcmd($config['destination'] . $file2);
$image1 = tempnam($config['tmp_dir'], "") . ".ppm";
$image2 = tempnam($config['tmp_dir'], "") . ".ppm";
$diff = tempnam($config['tmp_dir'], "") . ".ppm";
$cmd = "/home/xrosecky/projects/compare/compare -1 '{$image1}' -2 '{$image2}' '{$file1}' '{$file2}' '{$diff}'";
$result = exec_help("compare '{$file1}' '{$file2}'", $cmd);
$xml = simplexml_load_string($result);
$img1 = escapeshellcmd($config['destination'] . $xml->{"image1"}->{"checksum"} . ".png");
$img2 = escapeshellcmd($config['destination'] . $xml->{"image2"}->{"checksum"} . ".png");
$img_diff = escapeshellcmd($config['destination'] . $xml->{"image1"}->{"checksum"} . "_" . $xml->{"image2"}->{"checksum"} . ".png");
resize($image1, $img1);
resize($image2, $img2);
resize($diff, $img_diff);
jhove($xml->{"image1"}, $file1);
jhove($xml->{"image2"}, $file2);
return $xml;
}
示例13: validateAndSave
function validateAndSave($file)
{
$result = array();
if (!preg_match('/^image\\//', $file['type']) || !preg_match('/\\.(jpe?g|gif|png)$/', $file['name']) || getimagesize($file['tmp_name']) === FALSE) {
//then there is an error
$result['status'] = 'ERR';
$result['message'] = 'Invalid file format!';
} else {
if ($file['size'] > 110000) {
//if size is larger than what we expect
$result['status'] = 'ERR';
$result['message'] = 'Please choose a smaller file!';
} else {
if ($file['error'] != 0 || !is_uploaded_file($file['tmp_name'])) {
//if there is an unknown error or temporary uploaded file is not what we thought it was
$result['status'] = 'ERR';
$result['message'] = 'Unspecified error!';
} else {
//save file inside current directory using a safer version of its name
$save_path = preg_replace('/[^\\w\\.\\- ]/', '', $file['name']);
//thumbnail name is like filename-thumb.jpg
$thumb_path = preg_replace('/\\.(.+)$/', '', $save_path) . '-thumb.jpg';
if (!move_uploaded_file($file['tmp_name'], $save_path) or !resize($save_path, $thumb_path, 150)) {
$result['status'] = 'ERR';
$result['message'] = 'Unable to save file!';
} else {
//everything seems OK
$result['status'] = 'OK';
$result['message'] = 'Avatar changed successfully!';
//include new thumbnails `url` in our result and send to browser
$result['url'] = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']) . '/' . $thumb_path;
}
}
}
}
return $result;
}
示例14: uploadimageAction
function uploadimageAction()
{
if (POST) {
if (!empty($_FILES["logo"]["name"])) {
$v = explode(".", $_FILES["logo"]["name"]);
$base = "public/images/user/";
$logo = encode(rand(0, time())) . "." . $v[count($v) - 1];
if (is_file($base . $this->session->user["image"]) && $this->session->user["image"] != 'boy.gif' && $this->session->user["image"] != 'girl.gif') {
unlink($base . $this->session->user["image"]);
unlink($base . "icon/" . $this->session->user["image"]);
unlink($base . "thumb/" . $this->session->user["image"]);
}
resize($_FILES['logo']['tmp_name'], $base . "thumb/" . $logo, 150, 150);
resize($_FILES['logo']['tmp_name'], $base . "icon/" . $logo, 50, 50);
move_uploaded_file($_FILES['logo']['tmp_name'], $base . $logo);
$this->db->update("user", array("image" => $logo), "id=" . $this->session->user["id"]);
$this->session->error = array("Your profile pic changed.", 10, "yeppe");
$this->view->user["image"] = $this->session->user["image"] = $logo;
} else {
$this->view->error = array("Invalid image format uploaded", 10);
}
goBack();
}
}
示例15: editdata
function editdata()
{
require '../include/config.php';
$id = $_POST['id'];
$name = $_POST['txtname'];
$file = $_FILES['fle']['name'];
$file_tmp = $_FILES['fle']['tmp_name'];
$update = "UPDATE catalog SET catname = '{$name}'";
if ($file != "") {
check_size($file_tmp);
$imgname = md5($file);
$dot = substr($file, -3, 3);
$pic_name = $imgname . "-" . time() . "." . $dot;
resize($file_tmp, $pic_name, 150, "../../images/catproduct/tmp/");
copy($file_tmp, "../../images/catproduct/{$pic_name}");
$update .= ",catimg = '{$pic_name}'";
}
$update .= "where catid = '{$id}' ";
$dbCon->query($update) or die($dbCon->error);
$dbCon->close();
//echo $update;
header("Location: ../products/cat");
exit;
}