本文整理汇总了PHP中imagecopymerge函数的典型用法代码示例。如果您正苦于以下问题:PHP imagecopymerge函数的具体用法?PHP imagecopymerge怎么用?PHP imagecopymerge使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imagecopymerge函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: translucentWatermark
public static function translucentWatermark($originalImage, $watermark, $saveFile = null, $outputFileTipe = 'jpg')
{
$tempFolder = "temp/";
//$fileRandomValue = 0;
$cache = $tempFolder . $saveFile . '.' . $outputFileTipe;
// Load the stamp and the photo to apply the watermark to
if (strstr($originalImage, '.jpg') !== false) {
$im = imagecreatefromjpeg($originalImage);
} elseif (strstr($originalImage, '.png') !== false) {
$im = imagecreatefrompng($originalImage);
}
// First we create our stamp image manually from GD
$stamp = imagecreatetruecolor(100, 70);
imagefilledrectangle($stamp, 0, 0, 99, 69, 0xff);
imagefilledrectangle($stamp, 9, 9, 90, 60, 0xffffff);
//$im = imagecreatefromjpeg('photo.jpeg');
imagestring($stamp, 5, 20, 20, 'libGD', 0xff);
imagestring($stamp, 3, 20, 40, '(c) 2007-9', 0xff);
// Set the margins for the stamp and get the height/width of the stamp image
$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
// Merge the stamp onto our photo with an opacity of 50%
imagecopymerge($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp), 50);
// Save the image to file and free memory
imagepng($im, $cache);
imagedestroy($im);
}
示例2: overlay
/**
* Overlay an image onto the current image.
*
* @param string $image
* @param int $x
* @param int $y
* @throws Exception
* @return Gd
*/
public function overlay($image, $x = 0, $y = 0)
{
imagealphablending($this->image->resource(), true);
// Create an image resource from the overlay image.
if (stripos($image, '.gif') !== false) {
$overlay = imagecreatefromgif($image);
} else {
if (stripos($image, '.png') !== false) {
$overlay = imagecreatefrompng($image);
} else {
if (stripos($image, '.jp') !== false) {
$overlay = imagecreatefromjpeg($image);
} else {
throw new Exception('Error: The overlay image must be either a JPG, GIF or PNG.');
}
}
}
if ($this->opacity > 0) {
if ($this->opacity == 100) {
imagecopy($this->image->resource(), $overlay, $x, $y, 0, 0, imagesx($overlay), imagesy($overlay));
} else {
imagecopymerge($this->image->resource(), $overlay, $x, $y, 0, 0, imagesx($overlay), imagesy($overlay), $this->opacity);
}
}
return $this;
}
示例3: applyFilter
/**
* (non-PHPdoc)
* @see \imagemanipulation\filter\IImageFilter::applyFilter()
*/
public function applyFilter(ImageResource $resource)
{
if ($this->radius === 0) {
return;
}
$source_image = $resource->getResource();
$source_width = $resource->getX();
$source_height = $resource->getY();
$corner_image = imagecreatetruecolor($this->radius, $this->radius);
$clear_colour = imagecolorallocate($corner_image, 0, 0, 0);
imagecolortransparent($corner_image, $clear_colour);
$solid_colour = imagecolorallocate($corner_image, $this->color->getRed(), $this->color->getGreen(), $this->color->getBlue());
imagefill($corner_image, 0, 0, $solid_colour);
imagefilledellipse($corner_image, $this->radius, $this->radius, $this->radius * 2, $this->radius * 2, $clear_colour);
/*
* render the top-left, bottom-left, bottom-right, top-right corners by rotating and copying the mask
*/
imagecopymerge($source_image, $corner_image, 0, 0, 0, 0, $this->radius, $this->radius, 100);
$corner_image = imagerotate($corner_image, 90, 0);
imagecopymerge($source_image, $corner_image, 0, $source_height - $this->radius, 0, 0, $this->radius, $this->radius, 100);
$corner_image = imagerotate($corner_image, 90, 0);
imagecopymerge($source_image, $corner_image, $source_width - $this->radius, $source_height - $this->radius, 0, 0, $this->radius, $this->radius, 100);
$corner_image = imagerotate($corner_image, 90, 0);
imagecopymerge($source_image, $corner_image, $source_width - $this->radius, 0, 0, 0, $this->radius, $this->radius, 100);
}
示例4: applyFilter
/**
* Applies the filter to the resource
*
* @param ImageResource $aResource
*/
public function applyFilter(ImageResource $aResource)
{
$width = $aResource->getX();
$height = $aResource->getY();
$lineRes = imagecreatetruecolor($width, 1);
$bgc = imagecolorallocatealpha($lineRes, $this->backgroundColor->getRed(), $this->backgroundColor->getGreen(), $this->backgroundColor->getBlue(), $this->backgroundColor->getAlpha());
// Background color
imagefilledrectangle($lineRes, 0, 0, $width, 1, $bgc);
$rotateFilter = new ImageFilterRotate(180, $this->backgroundColor);
$rotateFilter->applyFilter($aResource);
$bg = imagecreatetruecolor($width, $this->height);
imagecopyresampled($bg, $aResource->getResource(), 0, 0, 0, 0, $width, $height, $width, $height);
$im = $bg;
$bg = imagecreatetruecolor($width, $this->height);
for ($x = 0; $x < $width; $x++) {
imagecopy($bg, $im, $x, 0, $width - $x, 0, 1, $this->height);
}
$im = $bg;
$in = 100 / $this->height;
for ($i = 0; $i <= $this->height; $i++) {
imagecopymerge($im, $lineRes, 0, $i, 0, 0, $width, 1, $this->startOpacity);
if ($this->startOpacity < 100) {
$this->startOpacity += $in;
}
}
imagecopymerge($im, $lineRes, 0, 0, 0, 0, $width, $this->divLineHeight, 100);
// Divider
$aResource->setResource($im);
}
示例5: imagecopymerge_alpha
public static function imagecopymerge_alpha($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct)
{
$cut = imagecreatetruecolor($src_w, $src_h);
imagecopy($cut, $dst_im, 0, 0, $dst_x, $dst_y, $src_w, $src_h);
imagecopy($cut, $src_im, 0, 0, $src_x, $src_y, $src_w, $src_h);
imagecopymerge($dst_im, $cut, $dst_x, $dst_y, 0, 0, $src_w, $src_h, $pct);
}
示例6: ApplyWatermark
function ApplyWatermark($watermark_path)
{
$this->watermark_path = $watermark_path;
// Determine image size and type
$size = getimagesize($this->image_path);
$size_x = $size[0];
$size_y = $size[1];
$image_type = $size[2];
// 1 = GIF, 2 = JPG, 3 = PNG
// load source image
$image = $this->ImageCreateFromType($image_type, $this->image_path);
// Determine watermark size and type
$wsize = getimagesize($watermark_path);
$watermark_x = $wsize[0];
$watermark_y = $wsize[1];
$watermark_type = $wsize[2];
// 1 = GIF, 2 = JPG, 3 = PNG
// load watermark
$watermark = $this->ImageCreateFromType($watermark_type, $watermark_path);
// where do we put watermark on the image?
$dest_x = $size_x - $watermark_x - $this->offset_x;
$dest_y = $size_y - $watermark_y - $this->offset_y;
imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_x, $watermark_y, 100);
$this->image =& $image;
$this->watermark =& $watermark;
$this->image_type = $image_type;
}
示例7: 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;
}
示例8: addWatermark
public function addWatermark($watermark)
{
if (!$this->gd) {
return;
}
$newGD = imagecreatetruecolor($this->width, $this->height);
// Preserves transparency between images
imagealphablending($newGD, true);
imagesavealpha($newGD, true);
imagecopy($newGD, $this->gd, 0, 0, 0, 0, $this->width, $this->height);
// Load the stamp and the photo to apply the watermark to
$stamp = imagecreatefrompng($watermark->getFullPath());
// Set the margins for the stamp and get the height/width of the stamp image
$sx = imagesx($stamp);
$sy = imagesy($stamp);
//bang in the middle
$dest_x = ceil($this->width / 2);
$dest_x -= ceil($watermark->width / 2);
$dest_y = ceil($this->height / 2);
$dest_y -= ceil($watermark->width / 2);
//be safe prevent negatives
if ($dest_x < 0) {
$dest_x = 0;
}
if ($dest_y < 0) {
$dest_y = 0;
}
// SS_Log::log('dest x: '.$dest_x.' dest y: '.$dest_y, SS_Log::ERR);
// Copy the stamp image onto our photo using the margin offsets and the photo
// width to calculate positioning of the stamp.
imagecopymerge($newGD, $stamp, $dest_x, $dest_y, 0, 0, imagesx($stamp), imagesy($stamp), 50);
$output = clone $this;
$output->setImageResource($newGD);
return $output;
}
示例9: make_captcha_img
function make_captcha_img()
{
global $CaptchaBGs;
$Length = 6;
$ImageHeight = 75;
$ImageWidth = 300;
$Chars = 'abcdefghjkmprstuvwxyzABCDEFGHJKLMPQRSTUVWXY23456789';
$CaptchaString = '';
for ($i = 0; $i < $Length; $i++) {
$CaptchaString .= $Chars[mt_rand(0, strlen($Chars) - 1)];
}
for ($x = 0; $x < $Length; $x++) {
$FontDisplay[$x]['size'] = mt_rand(24, 32);
$FontDisplay[$x]['top'] = mt_rand($FontDisplay[$x]['size'] + 5, $ImageHeight - $FontDisplay[$x]['size'] / 2);
$FontDisplay[$x]['angle'] = mt_rand(-30, 30);
$FontDisplay[$x]['font'] = get_font();
}
$Img = imagecreatetruecolor($ImageWidth, $ImageHeight);
$BGImg = imagecreatefrompng(SERVER_ROOT . '/captcha/' . $CaptchaBGs[mt_rand(0, count($CaptchaBGs) - 1)]);
imagecopymerge($Img, $BGImg, 0, 0, 0, 0, 300, 75, 50);
$ForeColor = imagecolorallocatealpha($Img, 255, 255, 255, 65);
for ($i = 0; $i < strlen($CaptchaString); $i++) {
$CharX = $ImageWidth / $Length * ($i + 1) - $ImageWidth / $Length * 0.75;
imagettftext($Img, $FontDisplay[$i]['size'], $FontDisplay[$i]['angle'], $CharX, $FontDisplay[$i]['top'], $ForeColor, $FontDisplay[$i]['font'], $CaptchaString[$i]);
}
header('Content-type: image/png');
imagepng($Img);
imagedestroy($Img);
return $CaptchaString;
}
示例10: process
/**
* (non-PHPdoc)
* @see \Simplify\Thumb\Plugin::process()
*/
protected function process(\Simplify\Thumb\Processor $thumb, $overlayImage = null, $dst_x = 0, $dst_y = 0, $src_x = 0, $src_y = 0, $src_w = null, $src_h = null, $pct = 0)
{
$overlay = \Simplify\Thumb\Functions::load($overlayImage);
$src_w = is_null($src_w) ? imagesx($overlay) : $src_w;
$src_h = is_null($src_h) ? imagesy($overlay) : $src_h;
imagecopymerge($thumb->image, $overlay, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct);
}
示例11: water
public static function water($source, $water, $saveName = null, $pos = 0, $alpha = 80, $quality = 100)
{
if (!FileUtil::fileExists($source) || !FileUtil::fileExists($water)) {
return false;
}
$sInfo = self::getImageInfo($source);
$wInfo = self::getImageInfo($water);
if ($sInfo["width"] < $wInfo["width"] || $sInfo["height"] < $wInfo["height"]) {
return false;
}
$sCreateFunction = "imagecreatefrom" . $sInfo["type"];
$sImage = $sCreateFunction($source);
$wCreateFunction = "imagecreatefrom" . $wInfo["type"];
$wImage = $wCreateFunction($water);
imagealphablending($wImage, true);
list($posX, $posY) = self::getPos($sInfo, $wInfo, $pos);
if ($wInfo["type"] == "png") {
imagecopy($sImage, $wImage, $posX, $posY, 0, 0, $wInfo["width"], $wInfo["height"]);
} else {
imagealphablending($wImage, true);
imagecopymerge($sImage, $wImage, $posX, $posY, 0, 0, $wInfo["width"], $wInfo["height"], $alpha);
}
$imageFun = "image" . $sInfo["type"];
if (!$saveName) {
$saveName = $source;
@unlink($source);
}
if ($sInfo["mime"] == "image/jpeg") {
$imageFun($sImage, $saveName, $quality);
} else {
$imageFun($sImage, $saveName);
}
imagedestroy($sImage);
return true;
}
示例12: drawCollage
/**
* Method draws a collage from friends avatars.
*
* @param $x
* @param $y
* @return resource
* @throws \Exception
*/
public function drawCollage($x, $y)
{
$username = 'k_riby';
$friends = $this->getFriendsList($username);
$posX = 0;
$posY = 0;
if (!isset($x) && !isset($y)) {
throw new \Exception("height and width must be set!");
}
$collage = imagecreatetruecolor($x, $y);
while ($posY <= $y) {
foreach ($friends['users'] as $user) {
$image = imagecreatefromstring(file_get_contents($user['profile_image_url']));
imagecopymerge($collage, $image, $posX, $posY, 5, 5, 50, 50, 100);
$posX += 50;
if ($posX >= $x) {
$posY += 50;
$posX = 0;
}
if ($posX >= $x && $posY >= $y) {
break;
}
}
}
return $collage;
}
示例13: water
public static function water($dst, $water, $save = NULL, $pos = 2, $alpha = 50)
{
//先保证两个图片存在
if (!file_exists($dst) || !file_exists($water)) {
return false;
}
//首先保证水印不能比待操作图片大
$dinfo = self::imageInfo($dst);
$winfo = self::imageInfo($water);
if ($winfo['height'] > $dinfo['height'] || $winfo['width'] > $dinfo['width']) {
return false;
}
//两张图,读到画布上,但是图片可能是png,可能是jpeg,用什么函数读
$dfunc = 'imagecreatefrom' . $dinfo['ext'];
$wfunc = 'imagecreatefrom' . $winfo['ext'];
if (!function_exists($dfunc) || !function_exists($wfunc)) {
return false;
}
//动态加载函数来创建画布
$dim = $dfunc($dst);
//创建待操作画布
$wim = $wfunc($water);
// 创建水印画布
//根据水印的位置,计算粘贴的坐标
switch ($pos) {
case 0:
//左上角
$posx = 0;
$posy = 0;
break;
case 1:
//右上角
$posx = $dinfo['width'] - $winfo['width'];
$posy = 0;
break;
case 3:
//左下角
$posx = 0;
$posy = $dinfo['height'] - $winfo['height'];
break;
default:
//右下角
$posx = $dinfo['width'] - $winfo['width'];
$posy = $dinfo['height'] - $winfo['height'];
break;
}
//加水印
imagecopymerge($dim, $wim, $posx, $posy, 0, 0, $winfo['width'], $winfo['height'], $alpha);
//保存
if (!$save) {
$save = $dst;
unlink($dst);
//删除原图
}
$createfunc = 'image' . $dinfo['ext'];
$createfunc($dim, $save);
imagedestroy($dim);
imagedestroy($wim);
return true;
}
示例14: create_watermark
function create_watermark($source_file_path, $output_file_path)
{
list($source_width, $source_height, $source_type) = getimagesize($source_file_path);
if ($source_type === NULL) {
return false;
}
switch ($source_type) {
case IMAGETYPE_GIF:
$source_gd_image = imagecreatefromgif($source_file_path);
break;
case IMAGETYPE_JPEG:
$source_gd_image = imagecreatefromjpeg($source_file_path);
break;
case IMAGETYPE_PNG:
$source_gd_image = imagecreatefrompng($source_file_path);
break;
default:
return false;
}
$overlay_gd_image = imagecreatefrompng(WATERMARK_OVERLAY_IMAGE);
$overlay_width = imagesx($overlay_gd_image);
$overlay_height = imagesy($overlay_gd_image);
imagecopymerge($source_gd_image, $overlay_gd_image, $source_width - $overlay_width, $source_height - $overlay_height, 0, 0, $overlay_width, $overlay_height, WATERMARK_OVERLAY_OPACITY);
imagejpeg($source_gd_image, $output_file_path, WATERMARK_OUTPUT_QUALITY);
imagedestroy($source_gd_image);
imagedestroy($overlay_gd_image);
//unlink($source_file_path);
}
示例15: by_lines
function by_lines($image, &$size_x, &$size_y)
{
$lines = array();
$size_x = imagesx($image->get_handle());
$size_y = imagesy($image->get_handle());
$dest_img = imagecreatetruecolor($size_x, $size_y);
imagecopymerge($dest_img, $image->get_handle(), 0, 0, 0, 0, $size_x, $size_y, 100);
// initialize line length counter
$ctr = 0;
for ($y = 0; $y < $size_y; $y++) {
$line = "";
for ($x = 0; $x < $size_x; $x++) {
// Save image pixel to the stream data
$rgb = ImageColorAt($dest_img, $x, $y);
$r = $rgb >> 16 & 0xff;
$g = $rgb >> 8 & 0xff;
$b = $rgb & 0xff;
$line .= sprintf("%02X%02X%02X", min(max($r, 0), 255), min(max($g, 0), 255), min(max($b, 0), 255));
// Increate the line length counter; check if stream line needs to be terminated
$ctr += 6;
if ($ctr > MAX_LINE_LENGTH) {
$line .= "\n";
$ctr = 0;
}
}
$lines[] = $line;
}
return $lines;
}