本文整理汇总了PHP中imageCopyResampled函数的典型用法代码示例。如果您正苦于以下问题:PHP imageCopyResampled函数的具体用法?PHP imageCopyResampled怎么用?PHP imageCopyResampled使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imageCopyResampled函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: image_createThumb
function image_createThumb($src, $dest, $maxWidth, $maxHeight, $quality = 75)
{
if (file_exists($src) && isset($dest)) {
// path info
$destInfo = pathInfo($dest);
// image src size
$srcSize = getImageSize($src);
// image dest size $destSize[0] = width, $destSize[1] = height
$srcRatio = $srcSize[0] / $srcSize[1];
// width/height ratio
$destRatio = $maxWidth / $maxHeight;
if ($destRatio > $srcRatio) {
$destSize[1] = $maxHeight;
$destSize[0] = $maxHeight * $srcRatio;
} else {
$destSize[0] = $maxWidth;
$destSize[1] = $maxWidth / $srcRatio;
}
// path rectification
if ($destInfo['extension'] == "gif") {
$dest = substr_replace($dest, 'jpg', -3);
}
// true color image, with anti-aliasing
$destImage = imageCreateTrueColor($destSize[0], $destSize[1]);
// imageAntiAlias($destImage,true);
// src image
switch ($srcSize[2]) {
case 1:
//GIF
$srcImage = imageCreateFromGif($src);
break;
case 2:
//JPEG
$srcImage = imageCreateFromJpeg($src);
break;
case 3:
//PNG
$srcImage = imageCreateFromPng($src);
break;
default:
return false;
break;
}
// resampling
imageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destSize[0], $destSize[1], $srcSize[0], $srcSize[1]);
// generating image
switch ($srcSize[2]) {
case 1:
case 2:
imageJpeg($destImage, $dest, $quality);
break;
case 3:
imagePng($destImage, $dest);
break;
}
return true;
} else {
return 'No such File';
}
}
示例2: resize_image_crop
function resize_image_crop($src_image, $width, $height)
{
$src_width = imageSX($src_image);
$src_height = imageSY($src_image);
$width = $width <= 0 ? $src_width : $width;
$height = $height <= 0 ? $src_height : $height;
$prop_width = $src_width / $width;
$prop_height = $src_height / $height;
if ($prop_height > $prop_width) {
$crop_width = $src_width;
$crop_height = round($prop_width * $height);
$srcX = 0;
$srcY = round($src_height / 2) - round($crop_height / 2);
} else {
$crop_width = round($prop_height * $width);
$crop_height = $src_height;
$srcX = round($src_width / 2) - round($crop_width / 2);
$srcY = 0;
}
$new_image = imageCreateTrueColor($width, $height);
$tmp_image = imageCreateTrueColor($crop_width, $crop_height);
imageCopy($tmp_image, $src_image, 0, 0, $srcX, $srcY, $crop_width, $crop_height);
imageCopyResampled($new_image, $tmp_image, 0, 0, 0, 0, $width, $height, $crop_width, $crop_height);
imagedestroy($tmp_image);
image_unsharp_mask($new_image);
return $new_image;
}
示例3: imageResize
function imageResize($file, $info, $destination)
{
$height = $info[1];
//высота
$width = $info[0];
//ширина
//определяем размеры будущего превью
$y = 150;
if ($width > $height) {
$x = $y * ($width / $height);
} else {
$x = $y / ($height / $width);
}
$to = imageCreateTrueColor($x, $y);
switch ($info['mime']) {
case 'image/jpeg':
$from = imageCreateFromJpeg($file);
break;
case 'image/png':
$from = imageCreateFromPng($file);
break;
case 'image/gif':
$from = imageCreateFromGif($file);
break;
default:
echo "No prevue";
break;
}
imageCopyResampled($to, $from, 0, 0, 0, 0, imageSX($to), imageSY($to), imageSX($from), imageSY($from));
imagepng($to, $destination);
imagedestroy($from);
imagedestroy($to);
}
示例4: create_thumb
function create_thumb($path, $thumb_path, $width = THUMB_WIDTH, $height = THUMB_HEIGHT)
{
$image_info = getImageSize($path);
// see EXIF for faster way
switch ($image_info['mime']) {
case 'image/gif':
if (imagetypes() & IMG_GIF) {
// not the same as IMAGETYPE
$o_im = @imageCreateFromGIF($path);
} else {
throw new Exception('GIF images are not supported');
}
break;
case 'image/jpeg':
if (imagetypes() & IMG_JPG) {
$o_im = @imageCreateFromJPEG($path);
} else {
throw new Exception('JPEG images are not supported');
}
break;
case 'image/png':
if (imagetypes() & IMG_PNG) {
$o_im = @imageCreateFromPNG($path);
} else {
throw new Exception('PNG images are not supported');
}
break;
case 'image/wbmp':
if (imagetypes() & IMG_WBMP) {
$o_im = @imageCreateFromWBMP($path);
} else {
throw new Exception('WBMP images are not supported');
}
break;
default:
throw new Exception($image_info['mime'] . ' images are not supported');
break;
}
list($o_wd, $o_ht, $html_dimension_string) = $image_info;
$ratio = $o_wd / $o_ht;
$t_ht = $width;
$t_wd = $height;
if (1 > $ratio) {
$t_wd = round($o_wd * $t_wd / $o_ht);
} else {
$t_ht = round($o_ht * $t_ht / $o_wd);
}
$t_wd = $t_wd < 1 ? 1 : $t_wd;
$t_ht = $t_ht < 1 ? 1 : $t_ht;
$t_im = imageCreateTrueColor($t_wd, $t_ht);
imageCopyResampled($t_im, $o_im, 0, 0, 0, 0, $t_wd, $t_ht, $o_wd, $o_ht);
imagejpeg($t_im, $thumb_path, 85);
chmod($thumb_path, 0664);
imageDestroy($o_im);
imageDestroy($t_im);
return array($t_wd, $t_ht);
}
示例5: generate_thumbnail
function generate_thumbnail($file, $mime)
{
global $config;
gd_capabilities();
list($file_type, $exact_type) = explode("/", $mime);
if (_JB_GD_INSTALLED && ($file_type = "image")) {
if ($exact_type != "gif" && $exact_type != "png" && $exact_type != "jpeg") {
return false;
}
if ($exact_type == "gif" && !_JB_GD_GIF) {
return false;
}
if ($exact_type == "png" && !_JB_GD_PNG) {
return false;
}
if ($exact_type == "jpeg" && !_JB_GD_JPG) {
return false;
}
// Load up the original and get size
// NOTE: use imageCreateFromString to avoid to have to check what type of image it is
$original = imageCreateFromString(file_get_contents($file));
$original_w = imagesX($original);
$original_h = imagesY($original);
// Only if the image is really too big, resize it
// NOTE: if image is smaller than target size, don't do anything.
// We *could* copy the original to filename_thumb, but since it's the same
// it would be a waste of precious resources
if ($original_w > $config['uploader']['thumb_w'] || $original_h > $config['uploader']['thumb_h']) {
// If original is wider than it's high, resize the width and vice versa
// NOTE: '>=' cause otherwise it's possible that $scale isn't computed
if ($original_w >= $original_h) {
$scaled_w = $config['uploader']['thumb_w'];
// Figure out how much smaller that target is than original
// and apply it to height
$scale = $config['uploader']['thumb_w'] / $original_w;
$scaled_h = ceil($original_h * $scale);
} elseif ($original_w <= $original_h) {
$scaled_h = $config['uploader']['thumb_h'];
$scale = $config['uploader']['thumb_h'] / $original_h;
$scaled_w = ceil($original_w * $scale);
}
} else {
// Break out of if($file_type = image) since no resize is possible
return false;
}
// Scale the image
$scaled = imageCreateTrueColor($scaled_w, $scaled_h);
imageCopyResampled($scaled, $original, 0, 0, 0, 0, $scaled_w, $scaled_h, $original_w, $original_h);
// Store thumbs in jpeg, hope no one minds the 100% quality lol
imageJpeg($scaled, $file . "_thumb", 100);
// Let's be nice to our server
imagedestroy($scaled);
imagedestroy($original);
return true;
}
}
示例6: draw
/**
* Draws the pie chart, with optional supersampled anti-aliasing.
* @param int $aa
*/
public function draw($aa = 4)
{
$this->canvas = imageCreateTrueColor($this->width, $this->height);
// Set anti-aliasing for the pie chart.
imageAntiAlias($this->canvas, true);
imageFilledRectangle($this->canvas, 0, 0, $this->width, $this->height, $this->_convertColor($this->backgroundColor));
$total = 0;
$sliceStart = -90;
// Start at 12 o'clock.
$titleHeight = $this->_drawTitle();
$legendWidth = $this->_drawLegend($titleHeight);
// Account for the space occupied by the legend and its padding.
$pieCentreX = ($this->width - $legendWidth) / 2;
// Account for the space occupied by the title.
$pieCentreY = $titleHeight + ($this->height - $titleHeight) / 2;
// 10% padding on the top and bottom of the pie.
$pieDiameter = round(min($this->width - $legendWidth, $this->height - $titleHeight) * 0.85);
foreach ($this->slices as $slice) {
$total += $slice['value'];
}
// If anti-aliasing is enabled, we supersample the pie to work around
// the fact that GD does not provide anti-aliasing natively.
if ($aa > 0) {
$ssDiameter = $pieDiameter * $aa;
$ssCentreX = $ssCentreY = $ssDiameter / 2;
$superSample = imageCreateTrueColor($ssDiameter, $ssDiameter);
imageFilledRectangle($superSample, 0, 0, $ssDiameter, $ssDiameter, $this->_convertColor($this->backgroundColor));
foreach ($this->slices as $slice) {
$sliceWidth = 360 * $slice['value'] / $total;
// Skip slices that are too small to draw / be visible.
if ($sliceWidth == 0) {
continue;
}
$sliceEnd = $sliceStart + $sliceWidth;
imageFilledArc($superSample, $ssCentreX, $ssCentreY, $ssDiameter, $ssDiameter, $sliceStart, $sliceEnd, $this->_convertColor($slice['color']), IMG_ARC_PIE);
// Move along to the next slice.
$sliceStart = $sliceEnd;
}
imageCopyResampled($this->canvas, $superSample, $pieCentreX - $pieDiameter / 2, $pieCentreY - $pieDiameter / 2, 0, 0, $pieDiameter, $pieDiameter, $ssDiameter, $ssDiameter);
imageDestroy($superSample);
} else {
// Draw the slices.
foreach ($this->slices as $slice) {
$sliceWidth = 360 * $slice['value'] / $total;
// Skip slices that are too small to draw / be visible.
if ($sliceWidth == 0) {
continue;
}
$sliceEnd = $sliceStart + $sliceWidth;
imageFilledArc($this->canvas, $pieCentreX, $pieCentreY, $pieDiameter, $pieDiameter, $sliceStart, $sliceEnd, $this->_convertColor($slice['color']), IMG_ARC_PIE);
// Move along to the next slice.
$sliceStart = $sliceEnd;
}
}
}
示例7: Resize
function Resize($maxwidth = 10000, $maxheight, $imagename, $filetype, $how = 'keep_aspect')
{
$target_temp_file = tempnam("jinn/temp", "gdlib_");
unlink($target_temp_file);
$target_temp_file .= '.' . $filetype;
if (!$maxheight) {
$maxheight = 10000;
}
if (!$maxwidth) {
$maxwidth = 10000;
}
$qual = 100;
$filename = $imagename;
$ext = $filetype;
list($curwidth, $curheight) = getimagesize($filename);
$factor = min($maxwidth / $curwidth, $maxheight / $curheight);
$sx = 0;
$sy = 0;
$sw = $curwidth;
$sh = $curheight;
$dx = 0;
$dy = 0;
$dw = $curwidth * $factor;
$dh = $curheight * $factor;
if ($ext == "JPEG") {
$src = ImageCreateFromJPEG($filename);
}
if ($ext == "GIF") {
$src = ImageCreateFromGIF($filename);
}
if ($ext == "PNG") {
$src = ImageCreateFromPNG($filename);
}
if (function_exists('ImageCreateTrueColor')) {
$dst = ImageCreateTrueColor($dw, $dh);
} else {
$dst = ImageCreate($dw, $dh);
}
if (function_exists('ImageCopyResampled')) {
imageCopyResampled($dst, $src, $dx, $dy, $sx, $sy, $dw, $dh, $sw, $sh);
} else {
imageCopyResized($dst, $src, $dx, $dy, $sx, $sy, $dw, $dh, $sw, $sh);
}
if ($ext == "JPEG") {
ImageJPEG($dst, $target_temp_file, $qual);
}
if ($ext == "PNG") {
ImagePNG($dst, $target_temp_file, $qual);
}
if ($ext == "GIF") {
ImagePNG($dst, $target_temp_file, $qual);
}
ImageDestroy($dst);
return $target_temp_file;
}
示例8: image_create_thumb
function image_create_thumb($img_file_path, $thumb_file_path, $width, $height)
{
if (($image = _image_load($img_file_path)) === false) {
return false;
}
$src_x = 0;
$src_y = 0;
$src_w = 0;
$src_h = 0;
$dst_w = 0;
$dst_h = 0;
_image_calculate_dimensions(imagesx($image), imagesy($image), $width, $height, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h);
//die('initial image width is ' . $original_width . ', requested width is ' . $width . ', new image width is ' . $new_img_width . ', src_x is ' . $src_x);
$thumb_image = imageCreateTrueColor($dst_w, $dst_h);
imageCopyResampled($thumb_image, $image, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
return _image_save($thumb_file_path, $thumb_image);
}
示例9: resize
function resize($width = 400, $height = 400, $aspectradio = true)
{
$o_wd = imagesx($this->image);
$o_ht = imagesy($this->image);
if (isset($aspectradio) && $aspectradio) {
$w = round($o_wd * $height / $o_ht);
$h = round($o_ht * $width / $o_wd);
if ($height - $h < $width - $w) {
$width =& $w;
} else {
$height =& $h;
}
}
$this->temp = imageCreateTrueColor($width, $height);
imageCopyResampled($this->temp, $this->image, 0, 0, 0, 0, $width, $height, $o_wd, $o_ht);
$this->sync();
return;
}
示例10: resizeImage
function resizeImage($file, $max_x, $max_y, $forcePng = false)
{
if ($max_x <= 0 || $max_y <= 0) {
$max_x = 5;
$max_y = 5;
}
$src = BASEDIR . '/avatars/' . $file;
list($width, $height, $type) = getImageSize($src);
$scale = min($max_x / $width, $max_y / $height);
$newWidth = $width * $scale;
$newHeight = $height * $scale;
$img = imagecreatefromstring(file_get_contents($src));
$black = imagecolorallocate($img, 0, 0, 0);
$resizedImage = imageCreateTrueColor($newWidth, $newHeight);
imagecolortransparent($resizedImage, $black);
imageCopyResampled($resizedImage, $img, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
imageDestroy($img);
unlink($src);
if (!$forcePng) {
switch ($type) {
case IMAGETYPE_JPEG:
imageJpeg($resizedImage, BASEDIR . '/avatars/' . $file);
break;
case IMAGETYPE_GIF:
imageGif($resizedImage, BASEDIR . '/avatars/' . $file);
break;
case IMAGETYPE_PNG:
imagePng($resizedImage, BASEDIR . '/avatars/' . $file);
break;
default:
imagePng($resizedImage, BASEDIR . '/avatars/' . $file);
break;
}
} else {
imagePng($resizedImage, BASEDIR . '/avatars/' . $file . '.png');
}
return;
}
示例11: show
/**
* Shows an image, possibly resized in the desired... size!
*
* Call it like: localhost/index.php?r=images/show&src=images/boats/3/boat.jpg&width=100
* If only one dimension is given, aspect ratio is maintained.
* If both dimensions are given, and are far from aspect ratio,
* the action tries to return a meaningful portion of the image.
*/
public function show($src = '', $width = '', $height = '')
{
// sometime in the future, we should cache the result of the resize to make it fast.
// we do not check for "is_file", because sometimes we are asked to resize remote images.
//if (!is_file($src))
// throw new CHttpException(404);
// if nothing given, simply redirect to the file.
if ($width == '' && $height == '' || $width == 0 && $height == 0) {
$this->_send_headers($src);
header('Location: ' . $src);
Yii::app()->end();
}
// we need to resize..
if (!($source_image = $this->_img_load($src))) {
throw new CHttpException(500);
}
$original_width = imagesx($source_image);
$original_height = imagesy($source_image);
$requested_width = $width;
$requested_height = $height;
$src_x = 0;
$src_y = 0;
$dst_x = 0;
$dst_y = 0;
$src_w = 0;
$src_h = 0;
$dst_w = 0;
$dst_h = 0;
$this->_calculate_dimensions($original_width, $original_height, $requested_width, $requested_height, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h);
//die('initial image width is ' . $original_width . ', requested width is ' . $width . ', new image width is ' . $new_img_width . ', src_x is ' . $src_x);
$target_image = imageCreateTrueColor($dst_w, $dst_h);
imageCopyResampled($target_image, $source_image, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
// send it.
$this->_send_headers($src);
$this->_img_send($target_image, $src);
}
示例12: copyResource
/**
* Copy an existing internal image resource, or part of it, to this Image instance
* @param resource existing internal image resource as source for the copy
* @param int x x-coordinate where the copy starts
* @param int y y-coordinate where the copy starts
* @param int resourceX starting x coordinate of the source image resource
* @param int resourceY starting y coordinate of the source image resource
* @param int width resulting width of the copy (not of the resulting image)
* @param int height resulting height of the copy (not of the resulting image)
* @param int resourceWidth width of the source image resource to copy
* @param int resourceHeight height of the source image resource to copy
* @return null
*/
protected function copyResource($resource, $x, $y, $resourceX, $resourceY, $width, $height, $resourceWidth, $resourceHeight)
{
if (!imageCopyResampled($this->resource, $resource, $x, $y, $resourceX, $resourceY, $width, $height, $resourceWidth, $resourceHeight)) {
if (!imageCopyResized($this->resource, $resource, $x, $y, $resourceX, $resourceY, $width, $height, $resourceWidth, $resourceHeight)) {
throw new ImageException('Could not copy the image resource');
}
}
$transparent = imageColorAllocate($this->resource, 0, 0, 0);
imageColorTransparent($this->resource, $transparent);
$this->width = $width;
$this->height = $height;
}
示例13: thumb_img3
function thumb_img3($src, $width, $height, $save_file)
{
$get_size = getImageReSize2($width, $height, imagesx($src), imagesy($src));
//$thumb = ImageCreate($get_size[0],$get_size[1]);
$thumb = imagecreatetruecolor($get_size[0], $get_size[1]);
// ImageCopyResized($thumb,$src,0,0,0,0,$get_size[0],$get_size[1],ImageSX($src),ImageSY($src));
imageCopyResampled($thumb, $src, 0, 0, 0, 0, $get_size[0], $get_size[1], ImageSX($src), ImageSY($src));
ImageJPEG($thumb, $save_file);
ImageDestroy($thumb);
}
示例14: imageResample
/**
* Resamples (convert/resize) an image file. You can specify a new width, height and type
* @param string $file Image path and file name
* @param int $w Width
* @param int $h Height
* @param string $type Supported image types: gif,png,jpg,bmp,xbmp,wbmp. Defaults to jpg
* @return boolean
*/
public static function imageResample($file, $w, $h, $type = null)
{
if (!function_exists('imagecreatefromstring')) {
Raxan::log('Function imagecreatefromstring does not exists - The GD image processing library is required.', 'warn', 'Raxan::imageResample');
return false;
}
$info = @getImageSize($file);
if ($info) {
// maintain aspect ratio
if ($h == 0) {
$h = $info[1] * ($w / $info[0]);
}
if ($w == 0) {
$w = $info[0] * ($h / $info[1]);
}
if ($w == 0 && $h == 0) {
$w = $info[0];
$h = $info[1];
}
// resize/resample image
$img = @imageCreateFromString(file_get_contents($file));
if (!$img) {
return false;
}
$newImg = function_exists('imagecreatetruecolor') ? imageCreateTrueColor($w, $h) : imageCreate($w, $h);
if (function_exists('imagecopyresampled')) {
imageCopyResampled($newImg, $img, 0, 0, 0, 0, $w, $h, $info[0], $info[1]);
} else {
imageCopyResized($newImg, $img, 0, 0, 0, 0, $w, $h, $info[0], $info[1]);
}
imagedestroy($img);
$type = !$type ? $info[2] : strtolower(trim($type));
if ($type == 1 || $type == 'gif') {
$f = 'imagegif';
} else {
if ($type == 3 || $type == 'png') {
$f = 'imagepng';
} else {
if ($type == 6 || $type == 16 || $type == 'bmp' || $type == 'xbmp') {
$f = 'imagexbm';
} else {
if ($type == 15 || $type == 'wbmp') {
$f = 'image2wbmp';
} else {
$f = 'imagejpeg';
}
}
}
}
if (function_exists($f)) {
$f($newImg, $file);
}
imagedestroy($newImg);
return true;
}
return false;
}
示例15: resizePhoto
function resizePhoto($vstup, $vystup, $width, $height, $aspectratio, $quality)
{
/*
$vstup //cesta k původnímu obrázku
$vystup //cesta ke zmenšenému obrázku
$width //šířka zmenšeného obrázku
$height //délka zmenšeného obrázku
$aspectratio //zachovávat poměr stran (0/1)
$quality //komprese (100 - nejlepsi) - doporucuji 75
*/
if (file_exists($vstup)) {
//nejprve zjistíme, zda-li byl zadán vstup a existuje
$vstup = ImageCreateFromJPEG($vstup);
//načteme si obrázek do proměnné
} else {
echo "resizePhoto: Nebyl zadán vstup !";
return false;
}
$vstup_wd = imagesx($vstup);
//zjistíme šířku původního obrázku
$vstup_ht = imagesy($vstup);
//zjistíme délku původního obrázku
if ($vstup_wd <= $width && $vstup_ht <= $height) {
//pokud je obrázek menší než požadovaná velikost nebudeme počítat nové hodnoty
$width = $vstup_wd;
$height = $vstup_ht;
} else {
if ($aspectratio) {
//pokud je zaplý aspect ratio spočítáme novou velikost v daném poměru
$w = round($vstup_wd * $height / $vstup_ht);
$h = round($vstup_ht * $width / $vstup_wd);
if ($height - $h < $width - $w) {
$width =& $w;
} else {
$height =& $h;
}
}
}
$temp = imageCreateTrueColor($width, $height);
//vytvoříme obrázek o rozměrech zmenšeného obrázku
imageCopyResampled($temp, $vstup, 0, 0, 0, 0, $width, $height, $vstup_wd, $vstup_ht);
//obrázky zkopíruje na sebe, takže dojde vlastně ke zmenšení výsledného obrázku
ImageJPEG($temp, $vystup, $quality);
//uložíme zmenšený obrázek na výstup
imagedestroy($vstup);
//uvolnime pamět
imagedestroy($temp);
//uvolnime pamět
}