使用imagick PHP为图像添加水印

时间:2016-07-12 16:31:24

标签: php imagick php-extension

我将watermark.png添加到original.png,但我有3个问题:

  1. 我想在右下角设置watermatk.png
  2. 我想调整watermark.png的大小并使其更小或更大
  3. 如果背景为白色,有没有办法让水印透明?
  4. <?php
    // Open the original image
    $image = new Imagick();
    $image->readImage("./man/original.png");
    
    // Open the watermark
    $watermark = new Imagick();
    $watermark->readImage("./man/watermark.png");
    
    // Overlay the watermark on the original image
    $image->compositeImage($watermark, imagick::COMPOSITE_OVER, 0, 0);
    
    // send the result to the browser
    header("Content-Type: image/" . $image->getImageFormat());
    echo $image;
    

1 个答案:

答案 0 :(得分:0)

实际上有一个&#34;水印&#34;将处理您的不透明度问题的命令。将它与重力+几何结合起来,以获得您想要的尺寸和位置。

StreamReader GET = new StreamReader(@"C:\Users\Matthew\Documents\sql.sql");

        string line;
        int fileId = 0;
        int lineId = 0;
        long fileLenght = 0;

        while ((line = GET.ReadLine()) != null)
        {
            lineId++;

            using (StreamWriter sw = File.AppendText(@"C:\Users\Matthew\Desktop\ye\" + fileId.ToString() + ".sql")) sw.WriteLine(line);

            if (lineId == 50000)
            {
                FileInfo f = new FileInfo(@"C:\Users\Matthew\Desktop\ye\" + fileId.ToString() + ".sql");
                fileLenght = f.Length;
                Console.Title = fileLenght.ToString();
                lineId = 0;
            }

            if (fileLenght > 50000000 && line.EndsWith(");"))
            {
                fileLenght = 0;
                fileId++;
                using (FileStream fs = File.Create(@"C:\Users\Matthew\Desktop\ye\" + fileId.ToString() + ".sql")) fs.Close();
                Console.WriteLine("Created: " + fileId.ToString());
            }

        }

        GET.Close();
        Console.WriteLine("Core - SQL is done.");

这样的事情。我没试过这个,但希望它可以帮助你。让我们知道它是如何运作的。