本文整理汇总了PHP中imagecopyresized函数的典型用法代码示例。如果您正苦于以下问题:PHP imagecopyresized函数的具体用法?PHP imagecopyresized怎么用?PHP imagecopyresized使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imagecopyresized函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addImage
function addImage()
{
global $db;
$stmt = $db->prepare('INSERT INTO images VALUES(NULL)');
$stmt->execute();
$id = $db->lastInsertId();
$originalFileName = "images/original/{$id}.jpg";
$smallFileName = "images/thumbs_small/{$id}.jpg";
$mediumFileName = "images/thumbs_medium/{$id}.jpg";
move_uploaded_file($_FILES['image']['tmp_name'], $originalFileName);
$original = imagecreatefromjpeg($originalFileName);
$width = imagesx($original);
$height = imagesy($original);
$square = min($width, $height);
$small = imagecreatetruecolor(200, 200);
imagecopyresized($small, $original, 0, 0, $width > $square ? ($width - $square) / 2 : 0, $height > $square ? ($height - $square) / 2 : 0, 200, 200, $square, $square);
imagejpeg($small, $smallFileName);
$mediumwidth = $width;
$mediumheight = $height;
if ($mediumwidth > 400) {
$mediumwidth = 400;
$mediumheight = $mediumheight * ($mediumwidth / $width);
}
$medium = imagecreatetruecolor($mediumwidth, $mediumheight);
imagecopyresized($medium, $original, 0, 0, 0, 0, $mediumwidth, $mediumheight, $width, $height);
imagejpeg($medium, $mediumFileName);
return $id;
}
示例2: getImage
private function getImage()
{
$image = imagecreatefromstring(file_get_contents($this->file['tmp_name']));
if ($this->currentExtension == 'jpg' || $this->currentExtension == 'jpeg') {
$exif = exif_read_data($this->file['tmp_name']);
if (!empty($exif['Orientation'])) {
switch ($exif['Orientation']) {
case 8:
$image = imagerotate($image, 90, 0);
break;
case 3:
$image = imagerotate($image, 180, 0);
break;
case 6:
$image = imagerotate($image, -90, 0);
break;
}
}
}
// Get new sizes
$width = imagesx($image);
$height = imagesy($image);
//list($width, $height) = getimagesize($this->file['tmp_name']);
list($newWidth, $newHeight) = $this->getScaledDimArray($image, 800);
// Load
$resizeImage = imagecreatetruecolor($newWidth, $newHeight);
// Resize
imagecopyresized($resizeImage, $image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
return $resizeImage;
}
示例3: embroidery2image
function embroidery2image($embroidery, $scale_post = 1, $scale_pre = false)
{
// Create image
$im = imagecreatetruecolor(ceil($embroidery->imageWidth * $scale_post), ceil($embroidery->imageHeight * $scale_post));
imagesavealpha($im, true);
imagealphablending($im, false);
$color = imagecolorallocatealpha($im, 255, 255, 255, 127);
imagefill($im, 0, 0, $color);
// Draw stitches
foreach ($embroidery->blocks as $block) {
$color = imagecolorallocate($im, $block->color->r, $block->color->g, $block->color->b);
$x = false;
foreach ($block->stitches as $stitch) {
if ($x !== false) {
imageline($im, ($x - $embroidery->min->x) * $scale_post, ($y - $embroidery->min->y) * $scale_post, ($stitch->x - $embroidery->min->x) * $scale_post, ($stitch->y - $embroidery->min->y) * $scale_post, $color);
}
$x = $stitch->x;
$y = $stitch->y;
}
}
// Scale finished image
if ($scale_pre) {
$im2 = imagecreatetruecolor($embroidery->imageWidth * $scale_post * $scale_pre, $embroidery->imageHeight * $scale_post * $scale_pre);
imagesavealpha($im2, true);
imagealphablending($im2, false);
imagecopyresized($im2, $im, 0, 0, 0, 0, $embroidery->imageWidth * $scale_post * $scale_pre, $embroidery->imageHeight * $scale_post * $scale_pre, $embroidery->imageWidth * $scale_post, $embroidery->imageHeight * $scale_post);
imagedestroy($im);
$im = $im2;
}
return $im;
}
示例4: create_thumbnail
function create_thumbnail($filename)
{
$percent = 0.1;
list($width, $height) = getimagesize("/var/www/amberandbrice.com/workspace/images/" . $filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;
$thumb = imagecreatetruecolor($newwidth, $newheight);
$ext = pathinfo($filename)['extension'];
echo "<h1>{$ext}</h1>";
switch ($ext) {
case 'jpg':
case 'jpeg':
case 'JPG':
$source = imagecreatefromjpeg("images/" . $filename);
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagejpeg($thumb, "./thumbs/" . $filename);
break;
case 'gif':
$source = imagecreatefromgif("images/" . $filename);
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagejpeg($thumb, "./thumbs/" . $filename);
break;
case 'png':
$source = imagecreatefrompng("images/" . $filename);
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagejpeg($thumb, "./thumbs/" . $filename);
break;
default:
die("image extension cannot be determined");
}
}
示例5: resize
/**
* Automatically resizes an image and returns formatted IMG tag
*
* @param string $path Path to the image file, relative to the webroot/img/ directory.
* @param integer $width Image of returned image
* @param integer $height Height of returned image
* @param boolean $aspect Maintain aspect ratio (default: true)
* @param array $htmlAttributes Array of HTML attributes.
* @param boolean $return Wheter this method should return a value or output it. This overrides AUTO_OUTPUT.
* @return mixed Either string or echos the value, depends on AUTO_OUTPUT and $return.
* @access public
*/
public function resize($path, $width, $height, $aspect = true, $htmlAttributes = array(), $return = false)
{
$types = array(1 => "gif", "jpeg", "png", "swf", "psd", "wbmp");
// used to determine image type
if (empty($htmlAttributes['alt'])) {
$htmlAttributes['alt'] = 'thumb';
}
// Ponemos alt default
$uploadsDir = 'uploads';
$fullpath = ROOT . DS . APP_DIR . DS . WEBROOT_DIR . DS . $uploadsDir . DS;
$url = ROOT . DS . APP_DIR . DS . WEBROOT_DIR . DS . $path;
if (!($size = getimagesize($url))) {
return;
}
// image doesn't exist
if ($aspect) {
// adjust to aspect.
if ($size[1] / $height > $size[0] / $width) {
// $size[0]:width, [1]:height, [2]:type
$width = ceil($size[0] / $size[1] * $height);
} else {
$height = ceil($width / ($size[0] / $size[1]));
}
}
$relfile = $this->webroot . $uploadsDir . '/' . $this->cacheDir . '/' . $width . 'x' . $height . '_' . basename($path);
// relative file
$cachefile = $fullpath . $this->cacheDir . DS . $width . 'x' . $height . '_' . basename($path);
// location on server
if (file_exists($cachefile)) {
$csize = getimagesize($cachefile);
$cached = $csize[0] == $width && $csize[1] == $height;
// image is cached
if (@filemtime($cachefile) < @filemtime($url)) {
// check if up to date
$cached = false;
}
} else {
$cached = false;
}
if (!$cached) {
$resize = $size[0] > $width || $size[1] > $height || ($size[0] < $width || $size[1] < $height);
} else {
$resize = false;
}
if ($resize) {
$image = call_user_func('imagecreatefrom' . $types[$size[2]], $url);
if (function_exists("imagecreatetruecolor") && ($temp = imagecreatetruecolor($width, $height))) {
imagecopyresampled($temp, $image, 0, 0, 0, 0, $width, $height, $size[0], $size[1]);
} else {
$temp = imagecreate($width, $height);
imagecopyresized($temp, $image, 0, 0, 0, 0, $width, $height, $size[0], $size[1]);
}
call_user_func("image" . $types[$size[2]], $temp, $cachefile);
imagedestroy($image);
imagedestroy($temp);
} else {
//copy($url, $cachefile);
}
return $this->output(sprintf($this->Html->tags['image'], $relfile, $this->Html->_parseAttributes($htmlAttributes, null, '', ' ')), $return);
}
示例6: outputPreview
/**
* @desc ������� ������ �����������
* @return
*/
function outputPreview($szContent, $szMime)
{
$source = imagecreatefromstring($szContent);
$nSourceHeight = imagesy($source);
$nSourceWidth = imagesx($source);
// �������� ������ � ������
if (DAO_IMAGE_THUMBNAIL_X == 0) {
$szHeight = DAO_IMAGE_THUMBNAIL_Y;
$szWidth = intval($nSourceWidth * DAO_IMAGE_THUMBNAIL_Y / $nSourceHeight);
} elseif (DAO_IMAGE_THUMBNAIL_Y == 0) {
$szWidth = DAO_IMAGE_THUMBNAIL_X;
$szHeight = intval($nSourceHeight * DAO_IMAGE_THUMBNAIL_X / $nSourceWidth);
} else {
$szWidth = DAO_IMAGE_THUMBNAIL_X;
$szHeight = DAO_IMAGE_THUMBNAIL_Y;
}
$thumb = imagecreatetruecolor($szWidth, $szHeight);
imagecopyresized($thumb, $source, 0, 0, 0, 0, $szWidth, $szHeight, $nSourceWidth, $nSourceHeight);
switch ($szMime) {
case 'image/jpeg':
imagejpeg($thumb);
break;
case 'image/png':
imagepng($thumb);
break;
case 'image/gif':
imagegif($thumb);
break;
default:
imagejpeg($thumb);
}
}
示例7: resize_image_gd
function resize_image_gd($src, $dest, $quality, $width, $height, $image_info)
{
global $convert_options;
$types = array(1 => "gif", 2 => "jpeg", 3 => "png");
if ($convert_options['convert_gd2']) {
$thumb = imagecreatetruecolor($width, $height);
} else {
$thumb = imagecreate($width, $height);
}
$image_create_handle = "imagecreatefrom" . $types[$image_info[2]];
if ($image = $image_create_handle($src)) {
if ($convert_options['convert_gd2']) {
imagecopyresampled($thumb, $image, 0, 0, 0, 0, $width, $height, ImageSX($image), ImageSY($image));
} else {
imagecopyresized($thumb, $image, 0, 0, 0, 0, $width, $height, ImageSX($image), ImageSY($image));
}
if ($image_info[2] == 3) {
$quality = 9;
}
$image_handle = "image" . $types[$image_info[2]];
$image_handle($thumb, $dest, $quality);
imagedestroy($image);
imagedestroy($thumb);
}
return file_exists($dest) ? 1 : 0;
}
示例8: crearThumbnail
function crearThumbnail($uploaddir, $uploaddirthumbnails, $anchoImgThumbnail, $filename)
{
if (preg_match('/[.](jpg)$/', $filename)) {
$im = imagecreatefromjpeg($uploaddir . $filename);
} else {
if (preg_match('/[.](gif)$/', $filename)) {
$im = imagecreatefromgif($uploaddir . $filename);
} else {
if (preg_match('/[.](png)$/', $filename)) {
$im = imagecreatefrompng($uploaddir . $filename);
}
}
}
$ox = imagesx($im);
// ancho de la imagen
$oy = imagesy($im);
// alto de la imagen
$nx = $anchoImgThumbnail;
$ny = floor($oy * ($anchoImgThumbnail / $ox));
$nm = imagecreatetruecolor($nx, $ny);
imagecopyresized($nm, $im, 0, 0, 0, 0, $nx, $ny, $ox, $oy);
if (!file_exists($uploaddirthumbnails)) {
if (!mkdir($uploaddirthumbnails)) {
die("Hubo un problema al subir la foto.");
}
}
imagejpeg($nm, $uploaddirthumbnails . $filename);
return true;
}
示例9: img_resize
/**
* 压缩图像尺寸函数 imageresize
* @perem $src_name 原始图像名称(包含路径名)
* @perem $percent 压缩比例(如0.5为新图像宽高为原图一半)
* @return $new_name 返回压缩后图像名称(包含路径名)
* @caution:调用函数前请做好类型检查,尽限于gif、jpeg、jpg和png格式图像
*/
function img_resize($resize_percent, $src_file, $des_file)
{
try {
list($src_width, $src_height) = getimagesize($src_file);
$new_width = $src_width * $resize_percent;
$new_height = $src_height * $resize_percent;
$new_image = imagecreatetruecolor($new_width, $new_height);
$suff = strrchr($src_file, '.');
switch ($suff) {
case ".jpg":
case ".jpeg":
$src_image = imagecreatefromjpeg($src_file);
imagecopyresized($new_image, $src_image, 0, 0, 0, 0, $new_width, $new_height, $src_width, $src_height);
imagejpeg($new_image, $des_file, 75);
break;
case ".png":
$src_image = imagecreatefrompng($src_file);
imagecopyresized($new_image, $src_image, 0, 0, 0, 0, $new_width, $new_height, $src_width, $src_height);
imagepng($new_image, $des_file);
break;
case ".gif":
$src_image = imagecreatefromgif($src_file);
imagecopyresized($new_image, $src_image, 0, 0, 0, 0, $new_width, $new_height, $src_width, $src_height);
imagegif($new_image, $src_file);
break;
default:
return false;
break;
}
} catch (Exception $e) {
Log::write("ImgResize::resize() exception: " . $e->getMessage(), "log");
return false;
}
return true;
}
示例10: scale
public function scale($dest, $width = null, $height = null, $force = false)
{
$im = $this->getIm();
if (null === $width && null === $height) {
$w = $width = imagesx($im);
$h = $height = imagesy($im);
} else {
if (false === $force) {
$w = imagesx($im);
$h = imagesy($im);
if (null === $width) {
$width = round($w * $height / $h);
} else {
if (null === $height) {
$height = round($h * $width / $w);
} else {
if ($w / $h > $width / $height) {
$height = round($h * $width / $w);
} else {
$width = round($w * $height / $h);
}
}
}
}
}
if (function_exists("imagecreatetruecolor") && ($ni = imagecreatetruecolor($width, $height))) {
imagecopyresampled($ni, $im, 0, 0, 0, 0, $width, $height, $w, $h);
} else {
$ni = imagecreate($width, $height);
imagecopyresized($ni, $im, 0, 0, 0, 0, $width, $height, $w, $h);
}
imagejpeg($ni, $dest);
ImageDestroy($ni);
}
示例11: createthumb
function createthumb($name, $filename, $new_w, $new_h)
{
// $src_img=null;
//$system=explode(".",$name);
if (preg_match("/jpg|jpeg|JPG/", $name)) {
$src_img = imagecreatefromjpeg($name);
}
if (preg_match("/png/", $name)) {
$src_img = imagecreatefrompng($name);
}
if (preg_match("/gif/", $name)) {
$src_img = imagecreatefromgif($name);
}
$old_x = imagesX($src_img);
$old_y = imagesY($src_img);
$thumb_w = (int) $new_w;
$thumb_h = (int) $new_h;
//$dst_img=imagecreate($thumb_w,$thumb_h);
$dst_img = imagecreatetruecolor($thumb_w, $thumb_h);
//imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
if (preg_match("/png|PNG/", $name)) {
imagepng($dst_img, $filename);
} else {
imagejpeg($dst_img, $filename, 100);
}
imagedestroy($dst_img);
imagedestroy($src_img);
}
示例12: create_thumbnail
/**
* create thumbnail. will return false on failure.
*/
function create_thumbnail($picture, $picture_thumb, $w)
{
// get src image
if (pathinfo($picture, PATHINFO_EXTENSION) == "jpg") {
$source_image = imagecreatefromjpeg($picture);
} else {
if (pathinfo($picture, PATHINFO_EXTENSION) == "png") {
$source_image = imagecreatefrompng($picture);
} else {
return false;
}
}
$width = imagesx($source_image);
$height = imagesy($source_image);
// calc height according to given width
$h = floor($height * ($w / $width));
// create virtual
$virtual_image = imagecreatetruecolor($w, $h);
// copy src image
imagecopyresized($virtual_image, $source_image, 0, 0, 0, 0, $w, $h, $width, $height);
// create thumbnail
if (pathinfo($picture, PATHINFO_EXTENSION) == 'jpg') {
imagejpeg($virtual_image, $picture_thumb, 83);
} elseif (pathinfo($picture, PATHINFO_EXTENSION) == 'png') {
imagepng($virtual_image, $picture_thumb);
}
return true;
}
示例13: fastimagecopyresampled
function fastimagecopyresampled($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h, $quality = 3)
{
// Plug-and-Play fastimagecopyresampled function replaces much slower imagecopyresampled.
// Just include this function and change all "imagecopyresampled" references to "fastimagecopyresampled".
// Typically from 30 to 60 times faster when reducing high resolution images down to thumbnail size using the default quality setting.
// Author: Tim Eckel - Date: 12/17/04 - Project: FreeRingers.net - Freely distributable.
//
// Optional "quality" parameter (defaults is 3). Fractional values are allowed, for example 1.5.
// 1 = Up to 600 times faster. Poor results, just uses imagecopyresized but removes black edges.
// 2 = Up to 95 times faster. Images may appear too sharp, some people may prefer it.
// 3 = Up to 60 times faster. Will give high quality smooth results very close to imagecopyresampled.
// 4 = Up to 25 times faster. Almost identical to imagecopyresampled for most images.
// 5 = No speedup. Just uses imagecopyresampled, highest quality but no advantage over imagecopyresampled.
if (empty($src_image) || empty($dst_image)) {
return false;
}
if ($quality <= 1) {
$temp = imagecreatetruecolor($dst_w + 1, $dst_h + 1);
imagecopyresized($temp, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w + 1, $dst_h + 1, $src_w, $src_h);
imagecopyresized($dst_image, $temp, 0, 0, 0, 0, $dst_w, $dst_h, $dst_w, $dst_h);
imagedestroy($temp);
} elseif ($quality < 5 && ($dst_w * $quality < $src_w || $dst_h * $quality < $src_h)) {
$tmp_w = $dst_w * $quality;
$tmp_h = $dst_h * $quality;
$temp = imagecreatetruecolor($tmp_w + 1, $tmp_h + 1);
imagecopyresized($temp, $src_image, $dst_x * $quality, $dst_y * $quality, $src_x, $src_y, $tmp_w + 1, $tmp_h + 1, $src_w, $src_h);
imagecopyresampled($dst_image, $temp, 0, 0, 0, 0, $dst_w, $dst_h, $tmp_w, $tmp_h);
imagedestroy($temp);
} else {
imagecopyresampled($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
}
//return true;
}
示例14: imagehex
/**
* Get image hash
* @param array $image
* @return array
*/
private function imagehex($image)
{
$size = getimagesize($image['path']);
$func = 'imagecreatefrom'.$image['type'];
$imageres = $func($image['path']);
$zone = imagecreate(20, 20);
imagecopyresized($zone, $imageres, 0, 0, 0, 0, 20, 20, $size[0], $size[1]);
$colormap = array();
$average = 0;
$result = array();
for($x=0; $x < 20; $x++)
{
for($y=0; $y < 20; $y++)
{
$color = imagecolorat($zone, $x, $y);
$color = imagecolorsforindex($zone, $color);
$colormap[$x][$y]= 0.212671 * $color['red'] + 0.715160 * $color['green'] + 0.072169 * $color['blue'];
$average += $colormap[$x][$y];
}
}
$average /= 400;
for($x=0; $x < 20; $x++)
{
for($y=0; $y < 20; $y++)
{
$result[]=($x < 10 ? $x : chr($x+97)) . ($y < 10 ? $y : chr($y+97)) . ($colormap[$x][$y]==0 ? '0' : round(2*($colormap[$x][$y] > $average ? $colormap[$x][$y]/$average:-1*$average/$colormap[$x][$y])));
}
}
return $result;
}
示例15: make_thumb
/**
* Create a jpg thumbnail from images of type jpg, png or gif.
*
* @param string $src Path to the original file
* @param string $ext Extension of the file
* @param string $dest Path to the place to save the thumbnail
* @param int $desired_width Width of the thumbnail (height is automatic depending on width)
* @return null|false
*/
function make_thumb($src, $ext, $dest, $desired_width)
{
// we don't want to work on too big images
// put the limit to 5 Mbytes
if (filesize($src) > 5000000) {
return false;
}
// the used fonction is different depending on extension
if (preg_match('/(jpg|jpeg)$/i', $ext)) {
$source_image = imagecreatefromjpeg($src);
} elseif (preg_match('/(png)$/i', $ext)) {
$source_image = imagecreatefrompng($src);
} elseif (preg_match('/(gif)$/i', $ext)) {
$source_image = imagecreatefromgif($src);
} else {
return false;
}
$width = imagesx($source_image);
$height = imagesy($source_image);
// find the "desired height" of this thumbnail, relative to the desired width
$desired_height = floor($height * ($desired_width / $width));
// create a new, "virtual" image
$virtual_image = imagecreatetruecolor($desired_width, $desired_height);
// copy source image at a resized size
imagecopyresized($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height);
// create the physical thumbnail image to its destination (85% quality)
imagejpeg($virtual_image, $dest, 85);
}