本文整理匯總了PHP中phpthumb_functions::ImageCopyRespectAlpha方法的典型用法代碼示例。如果您正苦於以下問題:PHP phpthumb_functions::ImageCopyRespectAlpha方法的具體用法?PHP phpthumb_functions::ImageCopyRespectAlpha怎麽用?PHP phpthumb_functions::ImageCopyRespectAlpha使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類phpthumb_functions
的用法示例。
在下文中一共展示了phpthumb_functions::ImageCopyRespectAlpha方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: WatermarkOverlay
public function WatermarkOverlay(&$gdimg_dest, &$img_watermark, $alignment = '*', $opacity = 50, $margin_x = 5, $margin_y = null)
{
if (is_resource($gdimg_dest) && is_resource($img_watermark)) {
$watermark_source_x = 0;
$watermark_source_y = 0;
$img_source_width = ImageSX($gdimg_dest);
$img_source_height = ImageSY($gdimg_dest);
$watermark_source_width = ImageSX($img_watermark);
$watermark_source_height = ImageSY($img_watermark);
$watermark_opacity_percent = max(0, min(100, $opacity));
$margin_y = is_null($margin_y) ? $margin_x : $margin_y;
$watermark_margin_x = $margin_x > 0 && $margin_x < 1 ? round((1 - $margin_x) * $img_source_width) : $margin_x;
$watermark_margin_y = $margin_y > 0 && $margin_y < 1 ? round((1 - $margin_y) * $img_source_height) : $margin_y;
if (preg_match('#^([0-9\\.\\-]*)x([0-9\\.\\-]*)$#i', $alignment, $matches)) {
$watermark_destination_x = intval($matches[1]);
$watermark_destination_y = intval($matches[2]);
} else {
switch ($alignment) {
case '*':
if ($gdimg_tiledwatermark = phpthumb_functions::ImageCreateFunction($img_source_width, $img_source_height)) {
ImageAlphaBlending($gdimg_tiledwatermark, false);
ImageSaveAlpha($gdimg_tiledwatermark, true);
$text_color_transparent = phpthumb_functions::ImageColorAllocateAlphaSafe($gdimg_tiledwatermark, 255, 0, 255, 127);
ImageFill($gdimg_tiledwatermark, 0, 0, $text_color_transparent);
// set the tiled image transparent color to whatever the untiled image transparency index is
// ImageColorTransparent($gdimg_tiledwatermark, ImageColorTransparent($img_watermark));
// a "cleaner" way of doing it, but can't handle the margin feature :(
// ImageSetTile($gdimg_tiledwatermark, $img_watermark);
// ImageFill($gdimg_tiledwatermark, 0, 0, IMG_COLOR_TILED);
// break;
// ImageFill($gdimg_tiledwatermark, 0, 0, ImageColorTransparent($gdimg_tiledwatermark));
// tile the image as many times as can fit
for ($x = $watermark_margin_x; $x < $img_source_width + $watermark_source_width; $x += $watermark_source_width + $watermark_margin_x) {
for ($y = $watermark_margin_y; $y < $img_source_height + $watermark_source_height; $y += $watermark_source_height + $watermark_margin_y) {
ImageCopy($gdimg_tiledwatermark, $img_watermark, $x, $y, 0, 0, min($watermark_source_width, $img_source_width - $x - $watermark_margin_x), min($watermark_source_height, $img_source_height - $y - $watermark_margin_y));
}
}
$watermark_source_width = ImageSX($gdimg_tiledwatermark);
$watermark_source_height = ImageSY($gdimg_tiledwatermark);
$watermark_destination_x = 0;
$watermark_destination_y = 0;
ImageDestroy($img_watermark);
$img_watermark = $gdimg_tiledwatermark;
}
break;
case 'T':
$watermark_destination_x = round($img_source_width / 2 - $watermark_source_width / 2 + $watermark_margin_x);
$watermark_destination_y = $watermark_margin_y;
break;
case 'B':
$watermark_destination_x = round($img_source_width / 2 - $watermark_source_width / 2 + $watermark_margin_x);
$watermark_destination_y = $img_source_height - $watermark_source_height - $watermark_margin_y;
break;
case 'L':
$watermark_destination_x = $watermark_margin_x;
$watermark_destination_y = round($img_source_height / 2 - $watermark_source_height / 2 + $watermark_margin_y);
break;
case 'R':
$watermark_destination_x = $img_source_width - $watermark_source_width - $watermark_margin_x;
$watermark_destination_y = round($img_source_height / 2 - $watermark_source_height / 2 + $watermark_margin_y);
break;
case 'C':
$watermark_destination_x = round($img_source_width / 2 - $watermark_source_width / 2);
$watermark_destination_y = round($img_source_height / 2 - $watermark_source_height / 2);
break;
case 'TL':
$watermark_destination_x = $watermark_margin_x;
$watermark_destination_y = $watermark_margin_y;
break;
case 'TR':
$watermark_destination_x = $img_source_width - $watermark_source_width - $watermark_margin_x;
$watermark_destination_y = $watermark_margin_y;
break;
case 'BL':
//echo '<pre>';
////var_dump($watermark_destination_x);
////var_dump($watermark_destination_y);
//var_dump($watermark_margin_x);
//var_dump($img_source_height);
//var_dump($watermark_source_height);
//var_dump($watermark_margin_y);
$watermark_destination_x = $watermark_margin_x;
$watermark_destination_y = $img_source_height - $watermark_source_height - $watermark_margin_y;
break;
case 'BR':
default:
$watermark_destination_x = $img_source_width - $watermark_source_width - $watermark_margin_x;
$watermark_destination_y = $img_source_height - $watermark_source_height - $watermark_margin_y;
break;
}
}
ImageAlphaBlending($gdimg_dest, false);
ImageSaveAlpha($gdimg_dest, true);
ImageSaveAlpha($img_watermark, true);
phpthumb_functions::ImageCopyRespectAlpha($gdimg_dest, $img_watermark, $watermark_destination_x, $watermark_destination_y, 0, 0, $watermark_source_width, $watermark_source_height, $watermark_opacity_percent);
return true;
}
return false;
}
示例2: WatermarkOverlay
function WatermarkOverlay(&$gdimg_dest, &$img_watermark, $alignment = '*', $opacity = 50, $margin = 5)
{
if (is_resource($gdimg_dest) && is_resource($img_watermark)) {
$watermark_source_x = 0;
$watermark_source_y = 0;
$img_source_width = ImageSX($gdimg_dest);
$img_source_height = ImageSY($gdimg_dest);
$watermark_source_width = ImageSX($img_watermark);
$watermark_source_height = ImageSY($img_watermark);
$watermark_opacity_percent = max(0, min(100, $opacity));
if ($margin < 1) {
$watermark_margin_percent = 1 - $margin;
} else {
$watermark_margin_percent = (100 - max(0, min(100, $margin))) / 100;
}
$watermark_margin_x = round((1 - $watermark_margin_percent) * $img_source_width);
$watermark_margin_y = round((1 - $watermark_margin_percent) * $img_source_height);
switch ($alignment) {
case '*':
if ($gdimg_tiledwatermark = phpthumb_functions::ImageCreateFunction($img_source_width, $img_source_height)) {
ImageAlphaBlending($gdimg_tiledwatermark, false);
if (phpthumb_functions::version_compare_replacement(phpversion(), '4.3.2', '>=')) {
ImageSaveAlpha($gdimg_tiledwatermark, true);
}
$text_color_transparent = phpthumb_functions::ImageColorAllocateAlphaSafe($gdimg_tiledwatermark, 255, 0, 255, 127);
ImageFill($gdimg_tiledwatermark, 0, 0, $text_color_transparent);
// set the tiled image transparent color to whatever the untiled image transparency index is
// ImageColorTransparent($gdimg_tiledwatermark, ImageColorTransparent($img_watermark));
// a "cleaner" way of doing it, but can't handle the margin feature :(
// ImageSetTile($gdimg_tiledwatermark, $img_watermark);
// ImageFill($gdimg_tiledwatermark, 0, 0, IMG_COLOR_TILED);
// break;
// ImageFill($gdimg_tiledwatermark, 0, 0, ImageColorTransparent($gdimg_tiledwatermark));
// tile the image as many times as can fit
for ($x = $watermark_margin_x; $x < $img_source_width + $watermark_source_width; $x += round($watermark_source_width + (1 - $watermark_margin_percent) * $img_source_width)) {
for ($y = $watermark_margin_y; $y < $img_source_height + $watermark_source_height; $y += round($watermark_source_height + (1 - $watermark_margin_percent) * $img_source_height)) {
ImageCopy($gdimg_tiledwatermark, $img_watermark, $x, $y, 0, 0, min($watermark_source_width, $img_source_width - $x - (1 - $watermark_margin_percent) * $img_source_width), min($watermark_source_height, $img_source_height - $y - (1 - $watermark_margin_percent) * $img_source_height));
}
}
$watermark_source_width = ImageSX($gdimg_tiledwatermark);
$watermark_source_height = ImageSY($gdimg_tiledwatermark);
$watermark_destination_x = 0;
$watermark_destination_y = 0;
ImageDestroy($img_watermark);
$img_watermark = $gdimg_tiledwatermark;
}
break;
case 'T':
$watermark_destination_x = round($img_source_width / 2 - $watermark_source_width / 2 + $watermark_margin_x);
$watermark_destination_y = $watermark_margin_y;
break;
case 'B':
$watermark_destination_x = round($img_source_width / 2 - $watermark_source_width / 2 + $watermark_margin_x);
$watermark_destination_y = round(($img_source_height - $watermark_source_height) * $watermark_margin_percent);
break;
case 'L':
$watermark_destination_x = $watermark_margin_x;
$watermark_destination_y = round($img_source_height / 2 - $watermark_source_height / 2 + $watermark_margin_y);
break;
case 'R':
$watermark_destination_x = round(($img_source_width - $watermark_source_width) * $watermark_margin_percent);
$watermark_destination_y = round($img_source_height / 2 - $watermark_source_height / 2 + $watermark_margin_y);
break;
case 'C':
$watermark_destination_x = round($img_source_width / 2 - $watermark_source_width / 2);
$watermark_destination_y = round($img_source_height / 2 - $watermark_source_height / 2);
break;
case 'TL':
$watermark_destination_x = $watermark_margin_x;
$watermark_destination_y = $watermark_margin_y;
break;
case 'TR':
$watermark_destination_x = round(($img_source_width - $watermark_source_width) * $watermark_margin_percent);
$watermark_destination_y = $watermark_margin_y;
break;
case 'BL':
$watermark_destination_x = $watermark_margin_x;
$watermark_destination_y = round(($img_source_height - $watermark_source_height) * $watermark_margin_percent);
break;
case 'BR':
default:
$watermark_destination_x = round(($img_source_width - $watermark_source_width) * $watermark_margin_percent);
$watermark_destination_y = round(($img_source_height - $watermark_source_height) * $watermark_margin_percent);
break;
}
ImageAlphaBlending($gdimg_dest, false);
if (phpthumb_functions::version_compare_replacement(phpversion(), '4.3.2', '>=')) {
ImageSaveAlpha($gdimg_dest, true);
ImageSaveAlpha($img_watermark, true);
}
phpthumb_functions::ImageCopyRespectAlpha($gdimg_dest, $img_watermark, $watermark_destination_x, $watermark_destination_y, 0, 0, $watermark_source_width, $watermark_source_height, $watermark_opacity_percent);
return true;
}
return false;
}