2016-11-29 18 views
0

こんにちは私は3000枚の写真が入ったフォルダを持っています。自分のサイトのロゴを追加するスクリプトが必要です。画像を編集するスクリプトがありますが、画像を開いてプロクルを作るスクリプトが必要です。php写真編集

誰もがWindows用のプログラムを持っている場合

私のスクリプト

<?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); 
?> 

も私に送ってください。

+1

Adob​​e LightroomとPhotoshopでこれをやや簡単に行うことができます – JimL

+0

トゥルーリアルまたはデモをどのように持っていますか? – und3rc00d3

+0

Photoshopはファイル - 自動化でバッチ処理を行います。 Lightroomでは、ファイルを透かしでエクスポートするだけです。エクスポートオプションです – JimL

答えて

0

私はこのようにそれを行うだろう:

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に変換する必要があります)。しかし、私は今や怠惰で、うまくいきます!そして今、それはあなたの手にあります!