如何像 envato photodune 预览图像一样使用 PHP 和 GD 制作水印图像? [英] How do I to make watermark image with PHP and GD like envato photodune preview image?

查看:67
本文介绍了如何像 envato photodune 预览图像一样使用 PHP 和 GD 制作水印图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用 PHP 和 GD 库创建水印.

我想重复水印标志,每个重复标志之间有自动边距(空格),还有锯齿形位置.

是否可以创建连接每个水印标志的虚线水印?

结果是这样的:

<小时>

我已经使用循环函数和奇偶子句完成了锯齿形.

/** 实用程序$widthWatermark = imagesx($logo);$heightWatermark = imagesy($logo);$widthPhoto = imagesx($output);$heightPhoto = imagesy($output);*///$xLogoPosition = 0;//$yLogoPosition = 0;$__xRepeat = ceil($widthPhoto/$widthWatermark);$__yRepeat = ceil($heightPhoto/$heightWatermark);$margin = (int)self::$option['margin'];for ($i = 0; $i <= $__xRepeat; $i++) {如果 ($i % 2 === 0) {$pre_ii = 1;} 别的 {$pre_ii = 0;}对于 ($ii = 0; $ii <= $__yRepeat; $ii++) {$ii_zero = $ii - $pre_ii;如果 ($ii_zero % 2 === 0) {$y_xindent = $widthWatermark;}别的{$y_xindent = 0;}$this->imagecopymerge_alpha($output, $logo, ($xLogoPosition + $widthWatermark * $i + $y_xindent), ($yLogoPosition + $widthWatermark * $ii), 0, 0, ImageSX($logo), ImageSY($logo), self::$option['opacity']);}}

现在我专注于如何创建具有连接到彼此徽标的对角线位置的虚线.

我有一个来自

结果:

I would like to create watermark with PHP and GD library.

I would like to do repeating the watermark logo with auto margin(space) between each repeated logo, also zigzag position.

Is it possible to create dash line watermark that connect each watermark logo?

The result would be like this:


I have finished the zigzag by using loop function and odd even clause.

/*
             * utils
                $widthWatermark = imagesx($logo);
                $heightWatermark = imagesy($logo);
                $widthPhoto = imagesx($output);
                $heightPhoto = imagesy($output);
             */

            // $xLogoPosition = 0;
            // $yLogoPosition = 0;


            $__xRepeat = ceil($widthPhoto / $widthWatermark);
            $__yRepeat = ceil($heightPhoto / $heightWatermark);
            $margin = (int)self::$option['margin'];

            for ($i = 0; $i <= $__xRepeat; $i++) {

                if ($i % 2 === 0) { 
                    $pre_ii = 1;
                } else {
                    $pre_ii = 0;
                }

                for ($ii = 0; $ii <= $__yRepeat; $ii++) {

                    $ii_zero = $ii - $pre_ii;

                    if ($ii_zero % 2 === 0) {       
                        $y_xindent = $widthWatermark;                        
                    }else{
                        $y_xindent = 0;  
                    }

                    $this->imagecopymerge_alpha($output, $logo, ($xLogoPosition + $widthWatermark * $i + $y_xindent), ($yLogoPosition + $widthWatermark * $ii), 0, 0, ImageSX($logo), ImageSY($logo), self::$option['opacity']);
                }
            }

now I stuck at how to create dashed line that have diagonal position that connect to each other logo.

I have a hint from http://php.net/manual/en/function.imagedashedline.php but I don't how to use and combine it with my previous code that generate zigzag logo

解决方案

Edit

It turns out that PHP/GD actually has a function - imagesettile() - specifically to handle this situation.

I've modified my original answer to account for this:

<?php
// create php image of a 'dashed cross'.
$crossW = $crossH = 200;
$cross  = imagecreatetruecolor($crossW, $crossH);
imagefill($cross, 0, 0, 0x7fff00ff); // transparent magenta.
imagesetthickness($cross, 1);
imagesetstyle(
    $cross,
    array_merge(
        array_fill(0, 3, 0x7fff00ff), // transparent magenta.
        array_fill(0, 8, 0x60ffffff) // partially-transparent white.
    )
);
imageline($cross, 0, 0, $crossW, $crossH, IMG_COLOR_STYLED);
imageline($cross, $crossW, 0, 0, $crossH, IMG_COLOR_STYLED);

$imageFile = 'wm2.jpg';

// open the image file to be watermarked and store its height and width.
$image = imagecreatefromjpeg($imageFile);
$imWidth = imagesx($image);
$imHeight = imagesy($image);

// apply the cross pattern as a tile to the image file.
imagesettile($image, $cross);
imagefilledrectangle($image, 0, 0, $imWidth, $imHeight, IMG_COLOR_TILED);

header('Content-type: image/png');
imagepng($image);
imagedestroy($cross);
imagedestroy($image);
exit;

Input:

Result:

这篇关于如何像 envato photodune 预览图像一样使用 PHP 和 GD 制作水印图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆