PHP照片编辑



你好,我有一个带有3000张照片的文件夹,我需要一个脚本来添加我的网站徽标buttom the Image,我有脚本来编辑图像,但是我需要一个打开图像并制作的图像procces,

我的脚本

<?php
        $logo = imagecreatefrompng("logo.png");
        header('Content-type: image/jpg');
        $image = imagecreatefromjpeg("image.jpg");
        imagecopy($image, $logo, 132, 95, 0, 0, 25, 25);
        imagejpeg($image);
        imagedestroy($image);
?>

另外,如果有人有窗户程序,请发送给我。

我会这样做:

function add_png_logo(){
    $dir = APPPATH.'assets/img/'; # Where your PNG photos are
    $dirUpload = APPPATH.'assets/uploads/'; # Where they will be saved
    $baseUrl = 'http://127.0.0.1/tests/assets/uploads/'; # Base to link merged images
    # Where the work begins
    $iteractor = new DirectoryIterator($dir);
    $ext = ['png'];
    $i = 0;
    # Function to save individual files
    function save_png($getFilename,$getFilePath){
        $medida = array('width'=>'1024','height'=>'1024',);
        // Creates a temp image
        $TempPngFile = imagecreatetruecolor($medida['width'], $medida['height']);
        # Defines a transparent color to fill all image
        $TransparentColor = imagecolorallocatealpha($TempPngFile, 0, 0, 0, 127);
        imagefill($TempPngFile, 0, 0, $TransparentColor);
        # Forces transparency definition
        imagealphablending($TempPngFile, true);
        imagesavealpha($TempPngFile, true);
        # Open image
        $logo = imageCreateFromPng(APPPATH.'cache/mark.png');
        # Fix transparency definitions
        imageAlphaBlending($logo, true);
        imageSaveAlpha($logo, true);            
        # Open image
        $img2 = imageCreateFromPng($getFilename);
        # Forces transparency definition
        imageAlphaBlending($img2, true);
        imageSaveAlpha($img2, true);
        # insert $logo and $img2 in $TempPngFile and setting positioning
        imagecopy($TempPngFile, $img2, 0, 0, 0, 0, imagesx($img2), imagesy($img2));
        imagecopy($TempPngFile, $logo, 25, 25, 0, 0, imagesx($logo), imagesy($logo)); 
        # Save final image to $getFilePath
        imagepng($TempPngFile, $getFilePath);
        // Destroy images
        imageDestroy($TempPngFile);
        imageDestroy($logo);
        imageDestroy($img2);            
    }
    # Loop in $dir, get all PNG files to overlap $logo on left top
    foreach ($iteractor as $entry) {
        if ($entry->isFile()) {
            if (in_array($entry->getExtension(), $ext)) {
                $getFilename = $dir.$entry->getFilename();
                $getImageName = $entry->getFilename().'_'.$i++.'_.png';
                $getFilePath = $dirUpload.$getImageName;
                save_png($getFilename, $getFilePath);
                echo 'Created image: <a href="'.$baseUrl.$getImageName.'" target="_blank">'.$getImageName.'</a><br>';
            }
        }
    }
}

obs:它使用php-gd扩展名。可以肯定的是,在重叠文件之前,有一种方法可以将JPG转换为PNG(或者您应该首先将3000张照片转换为PNG),但是我现在太懒了,它有效!现在它在您的手上!

最新更新