本文整理汇总了PHP中imageCreateTrueColor函数的典型用法代码示例。如果您正苦于以下问题:PHP imageCreateTrueColor函数的具体用法?PHP imageCreateTrueColor怎么用?PHP imageCreateTrueColor使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imageCreateTrueColor函数的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: generate_png
function generate_png($file_path, $size, $stars, $value, $output = '')
{
$image_set = imagecreatefrompng($file_path);
$star_empty = imagecreatetruecolor($size, $size);
imagesavealpha($star_empty, true);
$star_empty_transparent = imagecolorallocatealpha($star_empty, 0, 0, 0, 127);
imagefill($star_empty, 0, 0, $star_empty_transparent);
$star_filled = imagecreatetruecolor($size, $size);
imagesavealpha($star_filled, true);
$star_filled_transparent = imagecolorallocatealpha($star_filled, 0, 0, 0, 127);
imagefill($star_filled, 0, 0, $star_filled_transparent);
imagecopy($star_empty, $image_set, 0, 0, 0, 0, $size, $size);
imagecopy($star_filled, $image_set, 0, 0, 0, $size * 2, $size, $size);
$image = imageCreateTrueColor($stars * $size, $size);
imagesavealpha($image, true);
$image_transparent = imagecolorallocatealpha($image, 0, 0, 0, 127);
imagefill($image, 0, 0, $image_transparent);
imageSetTile($image, $star_empty);
imagefilledrectangle($image, 0, 0, $stars * $size, $size, IMG_COLOR_TILED);
imageSetTile($image, $star_filled);
imagefilledrectangle($image, 0, 0, $value * $size, $size, IMG_COLOR_TILED);
if ($output == '') {
Header("Content-type: image/png");
imagepng($image);
} else {
imagepng($image, $output);
}
imagedestroy($image);
imagedestroy($image_set);
imagedestroy($star_empty);
imagedestroy($star_filled);
}
示例3: thumbnail
function thumbnail($PicPathIn, $PicPathOut, $PicFilenameIn, $PicFilenameOut, $neueHoehe, $Quality)
{
// Bilddaten ermitteln
$size = getimagesize("{$PicPathIn}" . "{$PicFilenameIn}");
$breite = $size[0];
$hoehe = $size[1];
$neueBreite = intval($breite * $neueHoehe / $hoehe);
if ($size[2] == 1) {
// GIF
$altesBild = ImageCreateFromGIF("{$PicPathIn}" . "{$PicFilenameIn}");
$neuesBild = imageCreateTrueColor($neueBreite, $neueHoehe);
imageCopyResized($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
imageJPEG($neuesBild, "{$PicPathOut}" . "{$PicFilenameOut}", $Quality);
}
if ($size[2] == 2) {
// JPG
$altesBild = ImageCreateFromJPEG("{$PicPathIn}" . "{$PicFilenameIn}");
$neuesBild = imageCreateTrueColor($neueBreite, $neueHoehe);
imageCopyResized($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
ImageJPEG($neuesBild, "{$PicPathOut}" . "{$PicFilenameOut}", $Quality);
}
if ($size[2] == 3) {
// PNG
$altesBild = ImageCreateFromPNG("{$PicPathIn}" . "{$PicFilenameIn}");
$neuesBild = imageCreateTrueColor($neueBreite, $neueHoehe);
imageCopyResized($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
ImageJPEG($neuesBild, "{$PicPathOut}" . "{$PicFilenameOut}", $Quality);
}
}
示例4: 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);
}
示例5: createThumb
public function createThumb($image, $tnumber, $twidth, $theight, $tformat, $quality = 100)
{
if (!($twidth && trim($twidth) != '' && is_numeric($twidth)) && !($theight && trim($theight) != '' && is_numeric($theight))) {
return false;
}
$path = $this->_pathinfo['dirname'];
$resImage = $this->_resource;
// Calcul Thumb Size
$values = $this->_prepareDimensions($this->_width, $this->_height, $twidth, $theight, $tformat);
list($thumbX, $thumbY, $newX, $newY, $thumbWidth, $thumbHeight, $newWidth, $newHeight) = $values;
// Add transparence for PNG
$thumbImage = imageCreateTrueColor($thumbWidth, $thumbHeight);
if ($this->_extension == 'png') {
imagealphablending($thumbImage, false);
}
// Generate thumb ressource
imagecopyresampled($thumbImage, $resImage, $thumbX, $thumbY, $newX, $newY, $thumbWidth, $thumbHeight, $newWidth, $newHeight);
// Set Folder
// $file_path ='';
if ($tnumber == 0) {
$thumbLocation = $path . '/' . $this->_pathinfo['basename'];
} else {
JCckDevHelper::createFolder($path . '/_thumb' . $tnumber);
$thumbLocation = $path . '/_thumb' . $tnumber . '/' . $this->_pathinfo['basename'];
}
// Create image
$this->_generateThumb($this->_extension, $thumbImage, $thumbLocation, $quality);
return true;
}
示例6: 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;
}
示例7: update
/**
* Crop image file and set coordinates
*/
public function update()
{
$x = fRequest::get('x', 'integer');
$y = fRequest::get('y', 'integer');
$w = fRequest::get('w', 'integer');
$h = fRequest::get('h', 'integer');
$img_w = fRequest::get('img_w', 'integer');
$img_h = fRequest::get('img_h', 'integer');
try {
// throw new Exception(sprintf('x=%d,y=%d,w=%d,h=%d,img_w=%d,img_h=%d', $x, $y, $w, $h, $img_w, $img_h));
$img_r = imagecreatefromjpeg($this->uploadfile);
$x = $x * imagesx($img_r) / $img_w;
$y = $y * imagesy($img_r) / $img_h;
$w = $w * imagesx($img_r) / $img_w;
$h = $h * imagesy($img_r) / $img_h;
$dst_r = imageCreateTrueColor($this->target_width, $this->target_height);
imagecopyresampled($dst_r, $img_r, 0, 0, $x, $y, $this->target_width, $this->target_height, $w, $h);
imagejpeg($dst_r, $this->avatarfile, $this->jpeg_quality);
$dst_r = imageCreateTrueColor($this->mini_width, $this->mini_height);
imagecopyresampled($dst_r, $img_r, 0, 0, $x, $y, $this->mini_width, $this->mini_height, $w, $h);
imagejpeg($dst_r, $this->minifile, $this->jpeg_quality);
Activity::fireUpdateAvatar();
$this->ajaxReturn(array('result' => 'success'));
} catch (Exception $e) {
$this->ajaxReturn(array('result' => 'failure', 'message' => $e->getMessage()));
}
}
示例8: resize
/**
* @param int $maxX
* @param int $maxY
* @param bool $ignoreAspectRatio 画像の縦横比を維持するか。
* @return Image
*/
public function resize($maxX = 180, $maxY = 180, $ignoreAspectRatio = false)
{
$width = $this->getWidth();
$height = $this->getHeight();
if ($ignoreAspectRatio === false) {
$resizeX = $maxX;
$resizeY = $maxY;
} elseif ($width < $height) {
$resizeX = ceil($maxX * $width / $height);
$resizeY = $maxY;
} else {
$resizeX = $maxX;
$resizeY = ceil($maxY * $height / $width);
}
// 透明色が指定されているとjpg保存時に透明色部が黒くなるのでその対策。
// MEMO: PNGで保存するなら
// imagealphablending($resize, false);
// imagesavealpha($resize, true);
$resizeGD = @imageCreateTrueColor($resizeX, $resizeY);
$alpha = imagecolortransparent($this->gd);
if ($alpha !== -1) {
$color = imagecolorallocate($resizeGD, 255, 255, 255);
imageFill($resizeGD, 0, 0, $color);
imageColorTransparent($resizeGD, $alpha);
} else {
imageAlphaBlending($resizeGD, true);
imageSaveAlpha($resizeGD, true);
$fill_color = imagecolorallocate($resizeGD, 255, 255, 255);
imageFill($resizeGD, 0, 0, $fill_color);
}
imageCopyResampled($resizeGD, $this->gd, 0, 0, 0, 0, $resizeX, $resizeY, $width, $height);
return new Image($resizeGD);
}
示例9: createImage
private function createImage($width = 100, $height = 100)
{
$dest = imageCreateTrueColor($width, $height);
// antialising funktion zum glätten verkleinerter grafiken
// funktioniert aus unerfindlichen gründen nicht
//imageantialias($dest, TRUE);
return $dest;
}
示例10: 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);
}
示例11: generate
/**
* @param string $name
* @param int $colorScheme
* @param int $backgroundStyle
*
* @return $this
*/
public function generate($name, $colorScheme, $backgroundStyle = null)
{
$name = strtoupper(substr($name, 0, $this->chars));
$bgColor = $this->colorSchemes[$colorScheme];
$this->avatar = imageCreateTrueColor($this->width, $this->height);
imageFill($this->avatar, 0, 0, $bgColor);
$this->drawString($name, 0xffffff);
return $this;
}
示例12: 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;
}
}
示例13: setUp
public function setUp()
{
if (!extension_loaded('gd')) {
$this->markTestSkipped('The GD extension is not available.');
return;
}
$this->factory = ImageFactory::getInstance();
$this->mockExtension = 'mock';
$this->mockResource = imageCreateTrueColor(50, 50);
}
示例14: generate
/**
* @param string $name
* @param int $colorScheme
* @param int $backgroundStyle
*
* @return $this
*/
public function generate($name, $colorScheme, $backgroundStyle)
{
list($bgColor1, $bgColor2, $textColor) = $this->colorSchemes[$colorScheme];
$this->avatar = imageCreateTrueColor($this->width, $this->height);
imageFill($this->avatar, 0, 0, $bgColor1);
$this->drawBG($bgColor2, $backgroundStyle);
$this->drawString($name, $textColor);
$this->copyOverlay();
return $this;
}
示例15: 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;
}
}
}