本文整理汇总了PHP中imagepalettecopy函数的典型用法代码示例。如果您正苦于以下问题:PHP imagepalettecopy函数的具体用法?PHP imagepalettecopy怎么用?PHP imagepalettecopy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imagepalettecopy函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Returns an image with a resized canvas
*
* The image is filled with $color. Use $scale to determine, when to resize.
*
* @param WideImage_Image $img
* @param smart_coordinate $width
* @param smart_coordinate $height
* @param smart_coordinate $left
* @param smart_coordinate $top
* @param int $color
* @param string $scale 'up', 'down', 'any'
* @return WideImage_Image
*/
function execute($img, $width, $height, $left, $top, $color, $scale)
{
$new_width = WideImage_Coordinate::fix($width, $img->getWidth());
$new_height = WideImage_Coordinate::fix($width, $img->getHeight());
if ($scale == 'down') {
$new_width = min($new_width, $img->getWidth());
$new_height = min($new_height, $img->getHeight());
} elseif ($scale == 'up') {
$new_width = max($new_width, $img->getWidth());
$new_height = max($new_height, $img->getHeight());
}
$new = WideImage::createTrueColorImage($new_width, $new_height);
if ($img->isTrueColor()) {
if ($color === null) {
$color = $new->allocateColorAlpha(0, 0, 0, 127);
}
} else {
imagepalettecopy($new->getHandle(), $img->getHandle());
if ($color === null) {
if ($img->isTransparent()) {
$new->copyTransparencyFrom($img);
$tc_rgb = $img->getTransparentColorRGB();
$color = $new->allocateColorAlpha($tc_rgb);
} else {
$color = $new->allocateColorAlpha(255, 0, 127, 127);
}
imagecolortransparent($new->getHandle(), $color);
}
}
$new->fill(0, 0, $color);
$x = WideImage_Coordinate::fix($left, $new->getWidth(), $img->getWidth());
$y = WideImage_Coordinate::fix($top, $new->getHeight(), $img->getHeight());
$img->copyTo($new, $x, $y);
return $new;
}
示例2: restoreGifAlphaColor
/**
* Workaround method for restoring alpha transparency for gif images
*
* @param resource $src
* @param resource $dest
* @return resource transparent gf color
*/
public static function restoreGifAlphaColor(&$src, &$dest)
{
$transparentcolor = imagecolortransparent($src);
if ($transparentcolor != -1) {
$colorcount = imagecolorstotal($src);
imagetruecolortopalette($dest, true, $colorcount);
imagepalettecopy($dest, $src);
imagefill($dest, 0, 0, $transparentcolor);
imagecolortransparent($dest, $transparentcolor);
}
return $transparentcolor;
}
示例3: execute
/**
* Returns an image with a resized canvas
*
* The image is filled with $color. Use $scale to determine, when to resize.
*
* @param WideImage_Image $img
* @param smart_coordinate $width
* @param smart_coordinate $height
* @param smart_coordinate $left
* @param smart_coordinate $top
* @param int $color
* @param string $scale 'up', 'down', 'any'
* @param boolean $merge
* @return WideImage_Image
*/
function execute($img, $width, $height, $left, $top, $color, $scale, $merge)
{
$new_width = WideImage_Coordinate::fix($width, $img->getWidth());
$new_height = WideImage_Coordinate::fix($height, $img->getHeight());
if ($scale == 'down') {
$new_width = min($new_width, $img->getWidth());
$new_height = min($new_height, $img->getHeight());
} elseif ($scale == 'up') {
$new_width = max($new_width, $img->getWidth());
$new_height = max($new_height, $img->getHeight());
}
$new = WideImage::createTrueColorImage($new_width, $new_height);
if ($img->isTrueColor()) {
if ($color === null) {
$color = $new->allocateColorAlpha(0, 0, 0, 127);
}
} else {
imagepalettecopy($new->getHandle(), $img->getHandle());
if ($img->isTransparent()) {
$new->copyTransparencyFrom($img);
$tc_rgb = $img->getTransparentColorRGB();
$t_color = $new->allocateColorAlpha($tc_rgb);
}
if ($color === null) {
if ($img->isTransparent()) {
$color = $t_color;
} else {
$color = $new->allocateColorAlpha(255, 0, 127, 127);
}
imagecolortransparent($new->getHandle(), $color);
}
}
$new->fill(0, 0, $color);
$x = WideImage_Coordinate::fix($left, $new->getWidth(), $img->getWidth());
$y = WideImage_Coordinate::fix($top, $new->getHeight(), $img->getHeight());
// blending for truecolor images
if ($img->isTrueColor()) {
$new->alphaBlending($merge);
}
// not-blending for palette images
if (!$merge && !$img->isTrueColor() && isset($t_color)) {
$new->getCanvas()->filledRectangle($x, $y, $x + $img->getWidth(), $y + $img->getHeight(), $t_color);
}
$img->copyTo($new, $x, $y);
return $new;
}
示例4: keepTransparent
function keepTransparent($des)
{
$image = $this->image;
if ($image->getFormat() == 'png') {
imagealphablending($des, false);
imagesavealpha($des, true);
} elseif ($image->getFormat() == 'gif') {
$gdimage =& $image->getImage();
$colorTransparent = imagecolortransparent($gdimage);
imagepalettecopy($gdimage, $des);
if ($colorTransparent > 0) {
imagefill($des, 0, 0, $colorTransparent);
imagecolortransparent($des, $colorTransparent);
}
imagetruecolortopalette($des, true, 256);
}
}
示例5: imagecopyresampled_adv
function imagecopyresampled_adv($image_type, &$dest, $source, $d_x, $d_y, $s_x, $s_y, $d_w, $d_h, $s_w, $s_h)
{
switch ($image_type) {
// Process GIF images
case 1:
$transcol = imagecolortransparent($source);
$dest = imagecreate($d_w, $d_h);
imagepalettecopy($dest, $source);
imagefill($dest, 0, 0, $transcol);
imagecolortransparent($dest, $transcol);
return imagecopyresized($dest, $source, $d_x, $d_y, $s_x, $s_y, $d_w, $d_h, $s_w, $s_h);
break;
// Process PNG images
// Process PNG images
case 3:
$dest = imageCreateTrueColor($d_w, $d_h);
imagealphablending($dest, false);
imagesavealpha($dest, true);
$transparent = imagecolorallocatealpha($dest, 255, 255, 255, 0);
//BOF - DokuMan - 2011-01-06 - imagecolortransparent much faster on big images
//for ($x = 0; $x < $d_w; $x++) {
// for ($y = 0; $y < $d_h; $y++) {
// imageSetPixel($dest, $x, $y, $transparent);
// }
//}
imagecolortransparent($dest, $transparent);
//EOF - DokuMan - 2011-01-06 - imagecolortransparent much faster on big images
return imagecopyresampled($dest, $source, $d_x, $d_y, $s_x, $s_y, $d_w, $d_h, $s_w, $s_h);
break;
// Any other images
// Any other images
default:
$dest = imageCreateTrueColor($d_w, $d_h);
return imagecopyresampled($dest, $source, $d_x, $d_y, $s_x, $s_y, $d_w, $d_h, $s_w, $s_h);
}
}
示例6: _createImage
/**
* Returns a new image for temporary processing
*
* @access private
* @param int $width Width of the new image
* @param int $height Height of the new image
* @param bool $trueColor Force which type of image to create
* @return resource A GD image resource
*/
private function _createImage($width = -1, $height = -1, $trueColor = null)
{
if ($width == -1) {
$width = $this->_img_w;
}
if ($height == -1) {
$height = $this->_img_h;
}
$new_img = null;
if (is_null($trueColor)) {
if (function_exists('imageistruecolor')) {
$createtruecolor = imageistruecolor($this->_hImage);
} else {
$createtruecolor = true;
}
} else {
$createtruecolor = $trueColor;
}
if ($createtruecolor && function_exists('imagecreatetruecolor')) {
$new_img = @imagecreatetruecolor($width, $height);
}
if (!$new_img) {
$new_img = imagecreate($width, $height);
imagepalettecopy($new_img, $this->_hImage);
}
if ($this->_itype != 'gif') {
imagealphablending($new_img, false);
imagesavealpha($new_img, true);
}
$color = imagecolortransparent($this->_hImage);
if ($color != -1) {
imagecolortransparent($new_img, $color);
imagefill($new_img, 0, 0, $color);
}
return $new_img;
}
示例7: imagerotatex
function imagerotatex($im, $r, $c)
{
$r = deg2rad($r);
$sx = imagesx($im);
$sy = imagesy($im);
$im2 = imagecreate($sx, $sy);
imagepalettecopy($im2, $im);
$dx = floor($sx / 2);
$dy = floor($sy / 2);
for ($x = 0; $x < $sx; $x++) {
for ($y = 0; $y < $sy; $y++) {
$xx = $x - $dx;
$yy = $y - $dy;
$x1 = round($xx * cos($r) + $yy * sin($r)) + $dx;
$y1 = round(-$xx * sin($r) + $yy * cos($r)) + $dy;
$p = imagecolorat($im, $x1, $y1);
if ($p !== $c) {
$p = 0;
}
imagesetpixel($im2, $x, $y, $p);
}
}
return $im2;
}
示例8: rotate
/**
* Rotate image by the given angle
* Uses a fast rotation algorythm for custom angles
* or lines copy for multiple of 90 degrees
*
* @param int $angle Rotation angle
* @param array $options array( 'autoresize'=>true|false,
* 'color_mask'=>array(r,g,b), named color or #rrggbb
* )
* @author Pierre-Alain Joye
* @return mixed none or a PEAR error object on error
* @see PEAR::isError()
*/
function rotate($angle, $options = null)
{
if (function_exists('imagerotate')) {
$white = imagecolorallocatealpha($this->imageHandle, 255, 255, 255, 127);
$this->imageHandle = imagerotate($this->imageHandle, $angle, $white);
return true;
}
if ($options == null) {
$autoresize = true;
$color_mask = array(105, 255, 255);
} else {
extract($options);
}
while ($angle <= -45) {
$angle += 360;
}
while ($angle > 270) {
$angle -= 360;
}
$t = deg2rad($angle);
if (!is_array($color_mask)) {
if ($color[0] == '#') {
$this->colorhex2colorarray($color_mask);
} else {
include_once 'Image/Transform/Driver/ColorDefs.php';
$color = isset($colornames[$color_mask]) ? $colornames[$color_mask] : false;
}
}
// Do not round it, too much lost of quality
$cosT = cos($t);
$sinT = sin($t);
$img =& $this->imageHandle;
$width = $max_x = $this->img_x;
$height = $max_y = $this->img_y;
$min_y = 0;
$min_x = 0;
$x1 = round($max_x / 2, 0);
$y1 = round($max_y / 2, 0);
if ($autoresize) {
$t = abs($t);
$a = round($angle, 0);
switch ((int) $angle) {
case 0:
$width2 = $width;
$height2 = $height;
break;
case 90:
$width2 = $height;
$height2 = $width;
break;
case 180:
$width2 = $width;
$height2 = $height;
break;
case 270:
$width2 = $height;
$height2 = $width;
break;
default:
$width2 = (int) abs(sin($t) * $height + cos($t) * $width);
$height2 = (int) abs(cos($t) * $height + sin($t) * $width);
}
$width2 -= $width2 % 2;
$height2 -= $height2 % 2;
$d_width = abs($width - $width2);
$d_height = abs($height - $height2);
$x_offset = $d_width / 2;
$y_offset = $d_height / 2;
$min_x2 = -abs($x_offset);
$min_y2 = -abs($y_offset);
$max_x2 = $width2;
$max_y2 = $height2;
}
$img2 = @$this->newImgPreserveAlpha(imagecreateTrueColor($width2, $height2));
if (!is_resource($img2)) {
return false;
/*PEAR::raiseError('Cannot create buffer for the rotataion.',
null, PEAR_ERROR_TRIGGER, E_USER_NOTICE);*/
}
$this->img_x = $width2;
$this->img_y = $height2;
imagepalettecopy($img2, $img);
$mask = imagecolorallocatealpha($img2, $color_mask[0], $color_mask[1], $color_mask[2], 127);
// use simple lines copy for axes angles
switch ((int) $angle) {
case 0:
imagefill($img2, 0, 0, $mask);
//.........这里部分代码省略.........
示例9: imagecopyresampled
imagecopyresampled($dst_img, $src_img, 0, 0, 0, $height_ori - $new_h, $new_w, $new_h, $new_w, $new_h);
} elseif ($thumbdetail == 4) {
imagecopyresampled($dst_img, $src_img, 0, 0, $width_ori - $new_w, $height_ori - $new_h, $new_w, $new_h, $new_w, $new_h);
} else {
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $new_w, $new_h, $width_ori, $height_ori);
}
}
$img = imagegif($dst_img);
imagedestroy($src_img);
imagedestroy($dst_img);
imagedestroy($img);
} elseif (substr($_GET['img'], -3) == 'png') {
header('Content-type: image/png');
$src_img = imagecreatefrompng($_image_);
$dst_img = imagecreatetruecolor($new_w, $new_h);
imagepalettecopy($dst_img, $src_img);
if ($crop and ($crop_factor > 0 and $crop_factor < 100)) {
imagecopyresampled($dst_img, $src_img, 0, 0, $x_coordinate, $y_coordinate, $new_w, $new_h, $crop_width, $crop_height);
} else {
if ($thumbdetail == 1) {
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $new_w, $new_h, $new_w, $new_h);
} elseif ($thumbdetail == 2) {
imagecopyresampled($dst_img, $src_img, 0, 0, $width_ori - $new_w, 0, $new_w, $new_h, $new_w, $new_h);
} elseif ($thumbdetail == 3) {
imagecopyresampled($dst_img, $src_img, 0, 0, 0, $height_ori - $new_h, $new_w, $new_h, $new_w, $new_h);
} elseif ($thumbdetail == 4) {
imagecopyresampled($dst_img, $src_img, 0, 0, $width_ori - $new_w, $height_ori - $new_h, $new_w, $new_h, $new_w, $new_h);
} else {
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $new_w, $new_h, $width_ori, $height_ori);
}
}
示例10: header
header("content-Type: image/jpeg");
header("cache-control: no-cache");
imageJpeg($dst_im);
imagedestroy($src_im);
imagedestroy($dst_im);
break;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// png形式
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// png形式
case "3":
$src_im = imagecreatefrompng($photo_path);
$colortransparent = imagecolortransparent($src_im);
if ($colortransparent > -1) {
$dst_im = $imagecreate($re_size[0], $re_size[1]);
imagepalettecopy($dst_im, $src_im);
imagefill($dst_im, 0, 0, $colortransparent);
imagecolortransparent($dst_im, $colortransparent);
$imageresize($dst_im, $src_im, 0, 0, 0, 0, $re_size[0], $re_size[1], $size[0], $size[1]);
} else {
$dst_im = $imagecreate($re_size[0], $re_size[1]);
$imageresize($dst_im, $src_im, 0, 0, 0, 0, $re_size[0], $re_size[1], $size[0], $size[1]);
imagetruecolortopalette($dst_im, false, imagecolorstotal($src_im));
}
header("content-Type: image/png");
header("cache-control: no-cache");
imagepng($dst_im);
imagedestroy($src_im);
imagedestroy($dst_im);
break;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
示例11: ResizeImageFile
function ResizeImageFile($sourceFile, &$destinationFile, $arSize, $resizeType = BX_RESIZE_IMAGE_PROPORTIONAL, $arWaterMark = array(), $jpgQuality = false, $arFilters = false)
{
$io = CBXVirtualIo::GetInstance();
if (!$io->FileExists($sourceFile)) {
return false;
}
$bNeedCreatePicture = false;
if ($resizeType != BX_RESIZE_IMAGE_EXACT && $resizeType != BX_RESIZE_IMAGE_PROPORTIONAL_ALT) {
$resizeType = BX_RESIZE_IMAGE_PROPORTIONAL;
}
if (!is_array($arSize)) {
$arSize = array();
}
if (!array_key_exists("width", $arSize) || intval($arSize["width"]) <= 0) {
$arSize["width"] = 0;
}
if (!array_key_exists("height", $arSize) || intval($arSize["height"]) <= 0) {
$arSize["height"] = 0;
}
$arSize["width"] = intval($arSize["width"]);
$arSize["height"] = intval($arSize["height"]);
$arSourceSize = array("x" => 0, "y" => 0, "width" => 0, "height" => 0);
$arDestinationSize = array("x" => 0, "y" => 0, "width" => 0, "height" => 0);
$arSourceFileSizeTmp = CFile::GetImageSize($sourceFile);
if (!in_array($arSourceFileSizeTmp[2], array(IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_GIF, IMAGETYPE_BMP))) {
return false;
}
if (class_exists("imagick") && function_exists('memory_get_usage')) {
//When memory limit reached we'll try to use ImageMagic
$memoryNeeded = round(($arSourceFileSizeTmp[0] * $arSourceFileSizeTmp[1] * $arSourceFileSizeTmp['bits'] * ($arSourceFileSizeTmp['channels'] > 0 ? $arSourceFileSizeTmp['channels'] : 1) / 8 + pow(2, 16)) * 1.65);
$memoryLimit = CUtil::Unformat(ini_get('memory_limit'));
if (memory_get_usage() + $memoryNeeded > $memoryLimit) {
if ($arSize["width"] <= 0 || $arSize["height"] <= 0) {
$arSize["width"] = $arSourceFileSizeTmp[0];
$arSize["height"] = $arSourceFileSizeTmp[1];
}
CFile::ScaleImage($arSourceFileSizeTmp[0], $arSourceFileSizeTmp[1], $arSize, $resizeType, $bNeedCreatePicture, $arSourceSize, $arDestinationSize);
if ($bNeedCreatePicture) {
$new_image = CTempFile::GetFileName(bx_basename($sourceFile));
CheckDirPath($new_image);
$im = new Imagick();
try {
$im->setSize($arDestinationSize["width"], $arDestinationSize["height"]);
$im->readImage($io->GetPhysicalName($sourceFile));
$im->setImageFileName($new_image);
$im->thumbnailImage($arDestinationSize["width"], $arDestinationSize["height"], true);
$im->writeImage();
$im->destroy();
} catch (ImagickException $e) {
$new_image = "";
}
if ($new_image != "") {
$sourceFile = $new_image;
$arSourceFileSizeTmp = CFile::GetImageSize($io->GetPhysicalName($sourceFile));
}
}
}
}
if ($io->Copy($sourceFile, $destinationFile)) {
switch ($arSourceFileSizeTmp[2]) {
case IMAGETYPE_GIF:
$sourceImage = imagecreatefromgif($io->GetPhysicalName($sourceFile));
$bHasAlpha = true;
break;
case IMAGETYPE_PNG:
$sourceImage = imagecreatefrompng($io->GetPhysicalName($sourceFile));
$bHasAlpha = true;
break;
case IMAGETYPE_BMP:
$sourceImage = CFile::ImageCreateFromBMP($io->GetPhysicalName($sourceFile));
$bHasAlpha = false;
break;
default:
$sourceImage = imagecreatefromjpeg($io->GetPhysicalName($sourceFile));
$bHasAlpha = false;
break;
}
$sourceImageWidth = intval(imagesx($sourceImage));
$sourceImageHeight = intval(imagesy($sourceImage));
if ($sourceImageWidth > 0 && $sourceImageHeight > 0) {
if ($arSize["width"] <= 0 || $arSize["height"] <= 0) {
$arSize["width"] = $sourceImageWidth;
$arSize["height"] = $sourceImageHeight;
}
CFile::ScaleImage($sourceImageWidth, $sourceImageHeight, $arSize, $resizeType, $bNeedCreatePicture, $arSourceSize, $arDestinationSize);
if ($bNeedCreatePicture) {
if (CFile::IsGD2()) {
$picture = ImageCreateTrueColor($arDestinationSize["width"], $arDestinationSize["height"]);
if ($arSourceFileSizeTmp[2] == IMAGETYPE_PNG) {
$transparentcolor = imagecolorallocatealpha($picture, 0, 0, 0, 127);
imagefilledrectangle($picture, 0, 0, $arDestinationSize["width"], $arDestinationSize["height"], $transparentcolor);
imagealphablending($picture, false);
imagecopyresampled($picture, $sourceImage, 0, 0, $arSourceSize["x"], $arSourceSize["y"], $arDestinationSize["width"], $arDestinationSize["height"], $arSourceSize["width"], $arSourceSize["height"]);
imagealphablending($picture, true);
} elseif ($arSourceFileSizeTmp[2] == IMAGETYPE_GIF) {
imagepalettecopy($picture, $sourceImage);
//Save transparency for GIFs
$transparentcolor = imagecolortransparent($sourceImage);
if ($transparentcolor >= 0 && $transparentcolor < imagecolorstotal($sourceImage)) {
$RGB = imagecolorsforindex($sourceImage, $transparentcolor);
//.........这里部分代码省略.........
示例12: ResizePicture
//.........这里部分代码省略.........
if (!file_exists($file) && !is_file($file)) {
return GetMessage("IBLOCK_BAD_FILE_NOT_FOUND");
}
$width = intval($arResize["WIDTH"]);
$height = intval($arResize["HEIGHT"]);
if ($width <= 0 && $height <= 0) {
return $arFile;
}
$orig = CFile::GetImageSize($file, true);
if (!is_array($orig)) {
return GetMessage("IBLOCK_BAD_FILE_NOT_PICTURE");
}
if ($width > 0 && $orig[0] > $width || $height > 0 && $orig[1] > $height) {
if ($arFile["COPY_FILE"] == "Y") {
$new_file = CTempFile::GetFileName(basename($file));
CheckDirPath($new_file);
$arFile["copy"] = true;
if (copy($file, $new_file)) {
$file = $new_file;
} else {
return GetMessage("IBLOCK_BAD_FILE_NOT_FOUND");
}
}
$width_orig = $orig[0];
$height_orig = $orig[1];
if ($width <= 0) {
$width = $width_orig;
}
if ($height <= 0) {
$height = $height_orig;
}
$height_new = $height_orig;
if ($width_orig > $width) {
$height_new = $width / $width_orig * $height_orig;
}
if ($height_new > $height) {
$width = $height / $height_orig * $width_orig;
} else {
$height = $height_new;
}
$image_type = $orig[2];
if ($image_type == IMAGETYPE_JPEG) {
$image = imagecreatefromjpeg($file);
} elseif ($image_type == IMAGETYPE_GIF) {
$image = imagecreatefromgif($file);
} elseif ($image_type == IMAGETYPE_PNG) {
$image = imagecreatefrompng($file);
} else {
return GetMessage("IBLOCK_BAD_FILE_UNSUPPORTED");
}
$image_p = imagecreatetruecolor($width, $height);
if ($image_type == IMAGETYPE_JPEG) {
if ($arResize["METHOD"] === "resample") {
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
} else {
imagecopyresized($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
}
if ($arResize["COMPRESSION"] > 0) {
imagejpeg($image_p, $file, $arResize["COMPRESSION"]);
} else {
imagejpeg($image_p, $file);
}
} elseif ($image_type == IMAGETYPE_GIF && function_exists("imagegif")) {
imagetruecolortopalette($image_p, true, imagecolorstotal($image));
imagepalettecopy($image_p, $image);
//Save transparency for GIFs
$transparentColor = imagecolortransparent($image);
if ($transparentColor >= 0 && $transparentColor < imagecolorstotal($image)) {
$transparentColor = imagecolortransparent($image_p, $transparentColor);
imagefilledrectangle($image_p, 0, 0, $width, $height, $transparentColor);
}
if ($arResize["METHOD"] === "resample") {
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
} else {
imagecopyresized($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
}
imagegif($image_p, $file);
} else {
//Save transparency for PNG
$transparentColor = imagecolorallocatealpha($image_p, 0, 0, 0, 127);
imagefilledrectangle($image_p, 0, 0, $width, $height, $transparentColor);
$transparentColor = imagecolortransparent($image_p, $transparentColor);
imagealphablending($image_p, false);
if ($arResize["METHOD"] === "resample") {
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
} else {
imagecopyresized($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
}
imagesavealpha($image_p, true);
imagepng($image_p, $file);
}
imagedestroy($image);
imagedestroy($image_p);
$arFile["size"] = filesize($file);
$arFile["tmp_name"] = $file;
return $arFile;
} else {
return $arFile;
}
}
示例13: resize
/**
* Resize image
*
* @access public
* @param int $new_width (px)
* @param int $new_height (px)
* @proportional bool $proportional
*/
public function resize($new_width = null, $new_height = null, $mode = 'auto')
{
if (is_null($new_width) and is_null($new_height)) {
throw new \Exception('specifiy output dimensions');
}
list($output_width, $output_height) = $this->get_output_dimensions($new_width, $new_height, $mode);
$this->image_resized = imagecreatetruecolor($output_width, $output_height);
if ($this->mime_type == 'image/gif' or $this->mime_type == 'image/png') {
$transparent_index = imagecolortransparent($this->image);
if ($transparent_index >= 0) {
// GIF
imagepalettecopy($this->image, $this->image_resized);
imagefill($this->image_resized, 0, 0, $transparent_index);
imagecolortransparent($this->image_resized, $transparent_index);
imagetruecolortopalette($this->image_resized, true, 256);
} else {
// PNG
imagealphablending($this->image_resized, false);
imagesavealpha($this->image_resized, true);
$transparent = imagecolorallocatealpha($this->image_resized, 255, 255, 255, 127);
imagefilledrectangle($this->image_resized, 0, 0, $output_width, $output_height, $transparent);
}
}
imagecopyresampled($this->image_resized, $this->image, 0, 0, 0, 0, $output_width, $output_height, $this->width, $this->height);
if ($mode == 'crop') {
$this->crop($output_width, $output_height, $new_width, $new_height);
}
}
示例14: GenerateThumbFile
function GenerateThumbFile($from_name, $to_name)
{
// if src is URL then download file first
$temp = false;
if (substr($from_name, 0, 7) == 'http://') {
$tmpfname = tempnam("tmp/", "TmP-");
$temp = @fopen($tmpfname, "w");
if ($temp) {
@fwrite($temp, @file_get_contents($from_name)) or die("Cannot download image");
@fclose($temp);
$from_name = $tmpfname;
} else {
die("Cannot create temp file");
}
}
// check if file exists
if (!file_exists($from_name)) {
die("Source image does not exist!");
}
// get source image size (width/height/type)
// orig_img_type 1 = GIF, 2 = JPG, 3 = PNG
list($orig_x, $orig_y, $orig_img_type, $img_sizes) = @GetImageSize($from_name);
// cut image if specified by user
if ($this->cut_x > 0) {
$orig_x = min($this->cut_x, $orig_x);
}
if ($this->cut_y > 0) {
$orig_y = min($this->cut_y, $orig_y);
}
// should we override thumb image type?
$this->image_type = $this->image_type != -1 ? $this->image_type : $orig_img_type;
// check for allowed image types
if ($orig_img_type < 1 or $orig_img_type > 3) {
die("Image type not supported");
}
if ($orig_x > $this->max_x or $orig_y > $this->max_y) {
// resize
$per_x = $orig_x / $this->max_x;
$per_y = $orig_y / $this->max_y;
if ($per_y > $per_x) {
$this->max_x = $orig_x / $per_y;
} else {
$this->max_y = $orig_y / $per_x;
}
} else {
// keep original sizes, i.e. just copy
if ($this->save_to_file) {
@copy($from_name, $to_name);
} else {
switch ($this->image_type) {
case 1:
header("Content-type: image/gif");
readfile($from_name);
break;
case 2:
header("Content-type: image/jpeg");
readfile($from_name);
break;
case 3:
header("Content-type: image/png");
readfile($from_name);
break;
}
}
return;
}
if ($this->image_type == 1) {
// should use this function for gifs (gifs are palette images)
$ni = imagecreate($this->max_x, $this->max_y);
} else {
// Create a new true color image
$ni = ImageCreateTrueColor($this->max_x, $this->max_y);
}
// Fill image with white background (255,255,255)
$white = imagecolorallocate($ni, 255, 255, 255);
imagefilledrectangle($ni, 0, 0, $this->max_x, $this->max_y, $white);
// Create a new image from source file
$im = $this->ImageCreateFromType($orig_img_type, $from_name);
// Copy the palette from one image to another
imagepalettecopy($ni, $im);
// Copy and resize part of an image with resampling
imagecopyresampled($ni, $im, 0, 0, 0, 0, $this->max_x, $this->max_y, $orig_x, $orig_y);
// srcW, srcH
// save thumb file
$this->SaveImage($ni, $to_name);
if ($temp) {
unlink($tmpfname);
// this removes the file
}
}
示例15: convertGdObject
protected function convertGdObject($gdObject)
{
//create new object with restricted palette
$newObject = imagecreate($this->width, $this->height);
$width = imagesx($gdObject);
$height = imagesy($gdObject);
//create separate resource for palette holding.
//this cannot be created in $newObject unfortunately due to GD conversion bug,
//so we have to use intermediate object
$palette = imagecreate($this->width, $this->height);
//assign sxg palette colors to palette holding resource
foreach ($this->splittedRgbPalette as $color) {
imagecolorallocate($palette, $color[0], $color[1], $color[2]);
}
//here is the trick: assign palette before copying
imagepalettecopy($newObject, $palette);
//copy truecolor source to our new object with resampling. colors get replaced with palette as well.
imagecopyresampled($newObject, $gdObject, 0, 0, 0, 0, $this->width, $this->height, $width, $height);
//trick: assign palette after copying as well
imagepalettecopy($newObject, $palette);
// header('Content-type: image/png');
// imagepng($newObject);
// exit;
return $newObject;
}