本文整理汇总了PHP中resizeImage函数的典型用法代码示例。如果您正苦于以下问题:PHP resizeImage函数的具体用法?PHP resizeImage怎么用?PHP resizeImage使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了resizeImage函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: resizeImageCond
function resizeImageCond($imagem, $maxw = 500, $maxh = 500, $watermarkArray = array(), $bg = "FFFFFF", $forceJPG = false)
{
$ih = @getimagesize($imagem);
if ($ih) {
$ow = $ih[0];
// original
$oh = $ih[1];
if (count($watermarkArray) > 0 && !is_array($watermarkArray[0]) && $watermarkArray[0][0] == "C" && $ow > $maxw && $oh >= $maxh) {
// will crop, so $w and $h are the max (if original image is larger or equal to the thumb)
$w = $maxw;
$h = $maxh;
} else {
// either NOT crop, or crop but the image is smaller
$w = $ow;
$h = $oh;
if ($maxw > 0) {
// width surpassed, limit it
if ($w > $maxw) {
$w = $maxw;
$h = floor($oh / $ow * $w);
}
}
if ($maxh > 0) {
// heiht surpassed, limit it
if ($h > $maxh) {
$h = $maxh;
$w = floor($ow / $oh * $h);
}
}
}
if ($w != $ow || $h != $oh || count($watermarkArray) > 0) {
// if reduce OR watermark present, proceed
$imagemtmp = $imagem . "tmp";
if (resizeImage($imagem, $imagemtmp, $w, $h, CONS_JPGQUALITY, $watermarkArray, $bg, $forceJPG)) {
@unlink($imagem);
locateFile($imagemtmp, $ext);
// the resizeImage added .jpg or .png as per required
if (!@copy($imagemtmp, $imagem)) {
@unlink($imagemtmp);
return 2;
// error copying temporary file to destination file
}
// save ok
$temp = umask(0);
chmod($imagem, 0775);
umask($temp);
@unlink($imagemtmp);
return 1;
// ok!
} else {
return 2;
}
// error
}
} else {
return 2;
}
return 0;
// no change required
}
示例2: hacknrollify
function hacknrollify($picfilename)
{
$logofilename = "logo.png";
$logoPicPath = "logopics/" . $logofilename;
$originalPicPath = "originalpics/" . $picfilename;
$editedfilename = "hnr_" . $picfilename;
$editedPicPath = "editedpics/" . $editedfilename;
// read the original image from file
$profilepic = imagecreatefromjpeg($originalPicPath);
$profilepicWidth = imagesx($profilepic);
$profilepicHeight = imagesy($profilepic);
// create the black image overlay
$blackoverlay = imagecreate($profilepicWidth, $profilepicHeight);
imagecolorallocate($blackoverlay, 0, 0, 0);
// then merge the black and profilepic
imagecopymerge($profilepic, $blackoverlay, 0, 0, 0, 0, $profilepicWidth, $profilepicHeight, 50);
imagedestroy($blackoverlay);
// merge the resized logo
$logo = resizeImage($logoPicPath, $profilepicWidth - 80, 999999);
imageAlphaBlending($logo, false);
imageSaveAlpha($logo, true);
$logoWidth = imagesx($logo);
$logoHeight = imagesy($logo);
$verticalOffset = $profilepicHeight / 2 - $logoHeight / 2;
$horizontalOffset = 40;
imagecopyresampled($profilepic, $logo, $horizontalOffset, $verticalOffset, 0, 0, $logoWidth, $logoHeight, $logoWidth, $logoHeight);
$mergeSuccess = imagejpeg($profilepic, $editedPicPath);
if (!$mergeSuccess) {
echo "Image merge failed!";
}
imagedestroy($profilepic);
imagedestroy($logo);
return $editedPicPath;
}
示例3: uploadImage
/**
* Insert image data to database (recoreded_data and thumbnail).
* First generate an unique image id, then insert image to recoreded_data and resized image to thubnail along with
* other given data
*/
function uploadImage($conn, $sensor_id, $date_created, $description)
{
$image_id = generateId($conn, "images");
if ($image_id == 0) {
return;
}
$image2 = file_get_contents($_FILES['file_image']['tmp_name']);
$image2tmp = resizeImage($_FILES['file_image']);
$image2Thumbnail = file_get_contents($image2tmp['tmp_name']);
// encode the stream
$image = base64_encode($image2);
$imageThumbnail = base64_encode($image2Thumbnail);
$sql = "INSERT INTO images (image_id, sensor_id, date_created, description, thumbnail, recoreded_data)\n VALUES(" . $image_id . ", " . $sensor_id . ", TO_DATE('" . $date_created . "', 'DD/MM/YYYY hh24:mi:ss'), '" . $description . "', empty_blob(), empty_blob())\n RETURNING thumbnail, recoreded_data INTO :thumbnail, :recoreded_data";
$result = oci_parse($conn, $sql);
$recoreded_dataBlob = oci_new_descriptor($conn, OCI_D_LOB);
$thumbnailBlob = oci_new_descriptor($conn, OCI_D_LOB);
oci_bind_by_name($result, ":recoreded_data", $recoreded_dataBlob, -1, OCI_B_BLOB);
oci_bind_by_name($result, ":thumbnail", $thumbnailBlob, -1, OCI_B_BLOB);
$res = oci_execute($result, OCI_DEFAULT) or die("Unable to execute query");
if ($recoreded_dataBlob->save($image) && $thumbnailBlob->save($imageThumbnail)) {
oci_commit($conn);
} else {
oci_rollback($conn);
}
oci_free_statement($result);
$recoreded_dataBlob->free();
$thumbnailBlob->free();
echo "New image is added with image_id ->" . $image_id . "<br>";
}
示例4: index
public function index()
{
if ($_SESSION['access'] > $this->access['rr']) {
die('Access denied');
}
if (isset($_POST['action']) && $_POST['action'] == 'save') {
$this->updateSlider();
}
if (isset($_SESSION['msg']) && $_SESSION['msg'] == 'success') {
$this->data['text_message'] = $this->language['changes_applied'];
$this->data['class_message'] = 'success';
unset($_SESSION['msg']);
}
if (isset($_SESSION['msg']) && $_SESSION['msg'] == 'denied') {
$this->data['text_message'] = $this->language['access_denied'];
$this->data['class_message'] = 'error';
unset($_SESSION['msg']);
}
$this->engine->document->addScript('template/js/qfinder/qfinder.js');
$slides = isset($this->params['slides']) ? $this->params['slides'] : array();
$this->data['slides'] = $slides;
resizeImage(ROOT_DIR . 'upload/images/no-image.jpg', 90, 80, false);
foreach ($slides as $id => $slide) {
$this->data['slides'][$id] = array('src' => $slide['src'], 'thumb' => resizeImage($slide['src'], 90, 80, false), 'link' => $slide['link']);
}
$this->data['breadcrumbs'][] = array('caption' => $this->language['home'], 'link' => ADM_PATH);
$this->data['breadcrumbs'][] = array('caption' => $this->language['modules'], 'link' => 'index.php?page=modules');
$this->data['breadcrumb_cur'] = $this->language['slider'];
$this->template = 'template/slider.tpl';
}
示例5: process
function process()
{
global $DB, $CFG, $MOBILE_LANGS, $DEFAULT_LANG, $MEDIA;
$cm = get_coursemodule_from_id('url', $this->id);
$this->url = $DB->get_record('url', array('id' => $cm->instance), '*', MUST_EXIST);
$context = context_module::instance($cm->id);
$this->md5 = md5($this->url->externalurl) . $this->id;
$eiffilename = extractImageFile($this->url->intro, 'mod_url', 'intro', '0', $context->id, $this->courseroot, $cm->id);
if ($eiffilename) {
$this->resource_image = "/images/" . resizeImage($this->courseroot . "/" . $eiffilename, $this->courseroot . "/images/" . $cm->id, $CFG->block_oppia_mobile_export_thumb_width, $CFG->block_oppia_mobile_export_thumb_height);
//delete original image
unlink($this->courseroot . "/" . $eiffilename) or die(get_string('error_file_delete', 'block_oppia_mobile_export'));
}
unset($eiffilename);
}
示例6: getUploadedImage
function getUploadedImage($width = null, $height = null)
{
$ret = false;
$img_taille = 0;
$img_nom = '';
$taille_max = 20000000;
$ret = is_uploaded_file($_FILES['Filedata']['tmp_name']);
if (!$ret) {
error_log('Problème de transfert (Erreur php : ' . $_FILES['Filedata'] . ')');
return false;
} else {
// Le fichier a bien été reçu
$img_taille = $_FILES['Filedata']['size'];
if ($img_taille > $taille_max) {
error_log("Trop gros !");
return false;
}
$img_nom = $_FILES['Filedata']['name'];
}
// Redimensionnement de l'image
// Hauteur image destination
$source_file = $_FILES['Filedata']['tmp_name'];
// Fichier d'origine
// Cacul des nouvelles dimensions
$fileParts = pathinfo($_FILES['Filedata']['name']);
if (substr_count(strtolower($fileParts['extension']), "jpg") > 0 || substr_count($fileParts['extension'], "jpeg") > 0) {
$source_image = imagecreatefromjpeg($source_file);
} else {
if (substr_count(strtolower($fileParts['extension']), "png") > 0) {
$source_image = imagecreatefrompng($source_file);
} else {
if (substr_count(strtolower($fileParts['extension']), "gif") > 0) {
$source_image = imagecreatefromgif($source_file);
} else {
return false;
}
}
}
if ($width == null && $height == null) {
ob_start();
imagejpeg($source_image);
$contents = ob_get_contents();
ob_end_clean();
return $contents;
} else {
return resizeImage($source_image, $width, $height);
}
}
示例7: resize
function resize()
{
$image = $_GET['image'];
$height = $_GET['height'];
$width = $_GET['width'];
$file = md5($image . $height . $width);
$image = strstr($image, '?', true) ?: $image;
$ext = parse_url($image);
$ext = pathinfo($ext['path'], PATHINFO_EXTENSION);
if (!file_exists(dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . $file . "." . $ext)) {
$output = resizeImage(dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . $file . "." . $ext, file_get_contents($image), $width, $height, 1, 'file');
}
header("HTTP/1.1 301 Moved Permanently");
header("Location: " . BASE_URL . "cache/" . $file . "." . $ext . "\r\n");
exit;
}
示例8: changeAvatar
function changeAvatar()
{
$post = isset($_POST) ? $_POST : array();
$max_width = "500";
$userId = isset($post['hdn-profile-id']) ? intval($post['hdn-profile-id']) : 0;
$path = 'images/tmp';
$valid_formats = array("jpg", "png", "gif", "bmp", "jpeg");
$name = $_FILES['photoimg']['name'];
$size = $_FILES['photoimg']['size'];
if (strlen($name)) {
list($txt, $ext) = explode(".", $name);
if (in_array($ext, $valid_formats)) {
if ($size < 1024 * 1024) {
$actual_image_name = 'avatar' . '_' . $userId . '.' . $ext;
$filePath = $path . '/' . $actual_image_name;
$tmp = $_FILES['photoimg']['tmp_name'];
if (move_uploaded_file($tmp, $filePath)) {
$width = getWidth($filePath);
$height = getHeight($filePath);
//Scale the image if it is greater than the width set above
if ($width > $max_width) {
$scale = $max_width / $width;
$uploaded = resizeImage($filePath, $width, $height, $scale);
} else {
$scale = 1;
$uploaded = resizeImage($filePath, $width, $height, $scale);
}
/*$res = saveAvatar(array(
'userId' => isset($userId) ? intval($userId) : 0,
'avatar' => isset($actual_image_name) ? $actual_image_name : '',
));*/
//mysql_query("UPDATE users SET profile_image='$actual_image_name' WHERE uid='$session_id'");
echo "<img id='photo' file-name='" . $actual_image_name . "' class='' src='" . $filePath . '?' . time() . "' class='preview'/>";
} else {
echo "failed";
}
} else {
echo "Image file size max 1 MB";
}
} else {
echo "Invalid file format..";
}
} else {
echo "Please select image..!";
}
exit;
}
示例9: getData
function getData()
{
$tmpName = $_FILES['file']['tmp_name'];
assertNotEmpty($tmpName, "missing file");
$imageWidth = getParameter("imageWidth");
$imageHeight = getParameter("imageHeight");
$contentType = getContentType();
debug($contentType);
if (($contentType == "image/jpeg" || $contentType == "image/x-png" || $contentType == "image/png" || $contentType == "image/gif") && !empty($imageWidth) && !empty($imageHeight)) {
resizeImage($tmpName, $imageWidth, $imageHeight);
}
$fp = fopen($tmpName, 'r');
$length = filesize($tmpName);
debug("File size: {$length}");
$content = fread($fp, $length);
fclose($fp);
return $content;
}
示例10: fillCategory
private function fillCategory($category_id)
{
$limit = $this->params['count_per_page'];
$start = ($this->engine->url->page_n - 1) * $limit;
$q = $this->engine->db->query("SELECT id, parent_id, caption_" . $_SESSION['lang'] . " as caption, description_" . $_SESSION['lang'] . " as description, text_" . $_SESSION['lang'] . " as `text`, title_" . $_SESSION['lang'] . " as title, kw_" . $_SESSION['lang'] . " as kw, descr_" . $_SESSION['lang'] . " as descr FROM " . DB_PREF . "materials WHERE id='" . (int) $category_id . "' AND is_category=1 AND enabled=1 ORDER BY date_added DESC");
if (empty($q->row)) {
$this->engine->ERROR_404 = true;
return false;
} else {
$category = $q->row;
$breadcrumbs = array();
$this->buildBreadcrumbs($category['id'], $breadcrumbs);
$this->data['breadcrumbs'][0] = array('caption' => '<i class="glyphicon glyphicon-home"></i>', 'link' => $this->engine->url->link('route=home'));
foreach ($breadcrumbs as $breadcrumb) {
$this->data['breadcrumbs'][] = array('caption' => $breadcrumb['caption_' . $_SESSION['lang']], 'link' => $this->engine->url->link('route=materials&material_id=' . $breadcrumb['id']));
}
$this->data['category'] = array('caption' => $category['caption'], 'description' => $category['description'], 'text' => $category['text']);
if ($category['title'] != '') {
$this->engine->document->setTitle($category['title']);
}
if ($category['kw'] != '') {
$this->engine->document->setKeywords($category['kw']);
}
if ($category['descr'] != '') {
$this->engine->document->setDescription($category['descr']);
}
$categories = $this->engine->db->query("SELECT id, caption_" . $_SESSION['lang'] . " as caption, description_" . $_SESSION['lang'] . " as description, text_" . $_SESSION['lang'] . " as text, preview FROM " . DB_PREF . "materials WHERE parent_id=" . (int) $category_id . " AND enabled=1 AND is_category = 1 ORDER BY date_added DESC")->rows;
$this->data['categories'] = array();
foreach ($categories as $category) {
$this->data['categories'][$category['id']] = array('link' => $this->engine->url->link('route=materials&material_id=' . $category['id']), 'caption' => $category['caption'], 'preview' => resizeImage($category['preview'], 100, 100), 'description' => $category['description'], 'text' => $category['text']);
}
$materials = $this->engine->db->query("SELECT id, caption_" . $_SESSION['lang'] . " as caption, description_" . $_SESSION['lang'] . " as description, preview, date_added FROM " . DB_PREF . "materials WHERE parent_id=" . (int) $category_id . " AND enabled = 1 AND is_category = 0 ORDER BY date_added DESC LIMIT " . $start . ", " . $limit)->rows;
$this->data['materials'] = array();
foreach ($materials as $material) {
$this->data['materials'][$material['id']] = array('link' => $this->engine->url->link('route=materials&material_id=' . $material['id']), 'caption' => $material['caption'], 'preview' => resizeImage($material['preview'], 150, 150), 'date_added' => $material['date_added'], 'description' => $material['description']);
}
$this->data['details_caption'] = $this->params['details_' . $_SESSION['lang']];
$page_count = $this->getPageCount((int) $category_id, (int) $this->params['count_per_page']);
$this->data['pagination'] = printPagination($page_count, $this->engine->uri);
$this->mode = 1;
$this->engine->ERROR_404 = false;
return true;
}
}
示例11: fileUpload
function fileUpload($imgFile)
{
$file_path = $_SESSION['rootDir'] . '/images/gallery/' . basename($imgFile["name"]);
if (fileExists($file_path)) {
if (move_uploaded_file($imgFile["tmp_name"], $file_path)) {
resizeImage($file_path);
return 'images/gallery/' . basename($imgFile["name"]);
} else {
$_SESSION['status'] = 'error';
$_SESSION['flashData'] = 'File can not be uploaded';
header('location:' . baseUrl . 'admin/gallery/');
exit;
}
} else {
$_SESSION['status'] = 'error';
$_SESSION['flashData'] = 'Same file cannot be uploaded twice';
header('location:' . baseUrl . 'admin/gallery/');
}
}
示例12: thumbsize
function thumbsize($file, $size)
{
if (!preg_match("/(\\.gif|\\.jpeg|.\\jpg|\\.png|\\.bmp)/i", $file)) {
return $url;
}
if ($size) {
if (!is_dir(THUMB_DIR . "/" . $size)) {
mkdir(THUMB_DIR . "/" . $size, 777);
}
$path = explode("/", $file);
$fullfile = array_pop($path);
$second = array_pop($path);
if (!is_dir(THUMB_DIR . "/" . $size . "/" . $second)) {
mkdir(THUMB_DIR . "/" . $size . "/" . $second, 777);
}
$wh = explode("_", $size);
if (count($wh) != 2) {
return $file;
}
$width = intval($wh[0]);
$height = intval($wh[1]);
if ($width == 0 || $height == 0) {
return $file;
}
$ext = substr($fullfile, strrpos($fullfile, '.') + 1);
$noext = substr($fullfile, 0, strrpos($fullfile, '.'));
$thumbfile = THUMB_DIR . "/" . $size . "/{$second}/" . "{$noext}" . "_{$width}" . "_{$height}" . "." . $ext;
if (file_exists($thumbfile)) {
return MPIC_1 . $thumbfile;
} else {
if (resizeImage($file, $width, $height, $thumbfile)) {
return MPIC_1 . $thumbfile;
}
}
} else {
return $url;
}
}
示例13: index
public function index()
{
if (!$this->engine->url->is_category) {
$this->engine->ERROR_404 = false;
$this->engine->document->setTitle($this->params['title_' . $_SESSION['lang']]);
$this->engine->document->setKeywords($this->params['kw_' . $_SESSION['lang']]);
$this->engine->document->setDescription($this->params['descr_' . $_SESSION['lang']]);
$this->data['leave_review_btn'] = $this->params['leave_review_btn_' . $_SESSION['lang']];
$this->data['form_caption'] = $this->params['form_caption_' . $_SESSION['lang']];
$this->data['name_placeholder'] = $this->params['name_placeholder_' . $_SESSION['lang']];
$this->data['email_placeholder'] = $this->params['email_placeholder_' . $_SESSION['lang']];
$this->data['review_placeholder'] = $this->params['review_placeholder_' . $_SESSION['lang']];
$this->data['post_btn'] = $this->params['post_btn_' . $_SESSION['lang']];
$this->data['cancel_btn'] = $this->params['cancel_btn_' . $_SESSION['lang']];
$this->data['error_name'] = $this->params['error_name_' . $_SESSION['lang']];
$this->data['error_text'] = $this->params['error_text_' . $_SESSION['lang']];
$reviews = $this->getReviews(0, 50);
foreach ($reviews as $review) {
$this->data['reviews'][] = array('name' => $review['name'], 'post' => $review['post'], 'rating' => $review['rating'], 'photo' => resizeImage($review['photo'], 150, 150));
}
$this->template = TEMPLATE . 'template/modules/site_reviews.tpl';
}
}
示例14: findPhoto
private function findPhoto($start = 1, $limit = 20)
{
$dir = dirname(dirname(__FILE__)) . ROOT_DIR . 'upload/images/photos/';
$photos = array();
$i = 0;
foreach (glob($dir . "*.*") as $filename) {
$i++;
if ($i > $limit + $start - 1) {
break;
}
$filepath = $filename;
$filepath = str_replace('\\', '/', $filepath);
$path_parts = pathinfo($filepath);
$photos[$i]['src'] = ROOT_DIR . 'upload/images/photos/' . $path_parts['basename'];
$photos[$i]['thumb'] = resizeImage(ROOT_DIR . 'upload/images/photos/' . $path_parts['basename'], 150, 150);
}
if ($start > 1) {
for ($i = 1; $i < $start; $i++) {
unset($photos[$i]);
}
}
return $photos;
}
示例15: save_image
/**
* 保存缩略图图片到本地
*
* @param string 图片原url
* @return string 图片保存名
*/
function save_image($image_source_url, $image_new_name)
{
//包含gd库,处理图片
include "fn_gd.php";
if (preg_match("/jpg/i", $image_source_url)) {
$src_im = imagecreatefromjpeg($image_source_url);
if (!$src_im) {
throw new Exception("载入jpeg图片错误!");
}
return resizeImage($src_im, 230, 230, 'images/', $image_new_name, '.jpg');
} else {
if (preg_match("/png/i", $image_source_url)) {
$src_im = imagecreatefrompng($image_source_url);
if (!$src_im) {
throw new Exception("载入png图片错误!");
}
return resizeImage($src_im, 230, 230, 'images/', $image_new_name, '.png');
} else {
if (preg_match("/gif/i", $image_source_url)) {
$src_im = imagecreatefromgif($image_source_url);
if (!$src_im) {
throw new Exception("载入gif图片错误!");
}
return resizeImage($src_im, 230, 230, 'images/', $image_new_name, '.gif');
}
}
}
throw new Exception("无法识别的图片类型!");
}