5

によって作成された画像ファイルに著作権情報を追加する方法はありますPHPか?

copyrightより明確にするために、Photoshop を使用してファイルに情報を追加できます。そのため、その を取得するpropertiesと、次のようなものが表示されます。

Windows 7 で開いた画像ファイルのファイル プロパティ

PHPでファイルの詳細情報を追加・編集したい。可能ですか?

編集:

ユーザー入力から画像を取得し、次の関数でサイズを変更します。

 function image_resize($src, $w, $h, $dst, $width, $height, $extension )
 {
   switch($extension){
     case 'bmp': $img = imagecreatefromwbmp($src); break;
     case 'gif': $img = imagecreatefromgif($src); break;
     case 'jpg': $img = imagecreatefromjpeg($src); break;
     case 'png': $img = imagecreatefrompng($src); break;
     default : return "Unsupported picture type!";
  }
   $new = imagecreatetruecolor($width, $height);
  // preserve transparency
    if($extension == "gif" or $extension == "png"){
     imagecolortransparent($new, imagecolorallocatealpha($new, 0, 0, 0, 127));
      imagealphablending($new, true);
     imagesavealpha($new, false);
   }
   imagecopyresampled($new, $img, 0, 0, 0, 0, $width, $height, $w, $h);
   imageinterlace($new,1);//for progressive jpeg image
   switch($extension){
     case 'bmp': imagewbmp($new, $dst); break;
     case 'gif': imagegif($new, $dst); break;
     case 'jpg': imagejpeg($new, $dst); break;
     case 'png': imagepng($new, $dst); break;
   }
   return true;
 }
4

1 に答える 1

4

PHP に JPEG ファイルの EXIF データを編集する機能がネイティブに含まれているとは思いませんが、EXIF データを読み書きできる PEAR 拡張機能があります。

pear channel-discover pearhub.org
pear install pearhub/PEL 

モジュールの Web サイトはhttp://lsolesen.github.io/pel/で、説明を設定する例はhttps://github.com/lsolesen/pel/blob/master/examples/edit-description.phpにあります。

アップデート:

pearhub.org サイトはダウンしているか、完全になくなっているようですが、GitHub からファイルをダウンロードできます (インストールやセットアップは不要で、autoload.phpファイルを含めるだけです)。

以下は、JPEG ファイルに著作権フィールドを設定する例です。GitHub からダウンロードしたファイルは、 というサブディレクトリに配置されpelますが、好きな場所に配置できます (require_once行を更新するだけです)。

<?php

// Make the PEL functions available
require_once 'pel/autoload.php';  // Update path if your checked out copy of PEL is elsewhere

use lsolesen\pel\PelJpeg;
use lsolesen\pel\PelTag;
use lsolesen\pel\PelEntryCopyright;

/*
 * Values for you to set
 */

// Path and name of file you want to edit
$input_file = "/tmp/image.jpg";

// Name of file to write output to
$output_file = "/tmp/altered.jpg";

// Copyright info to add
$copyright = "Eborbob 2015";


/*
 * Do the work
 */

// Load the image into PEL
$pel = new PelJpeg($input_file);

// Get the EXIF data (See the PEL docs to understand this)
$ifd = $pel->getExif()->getTiff()->getIfd();

// Get the copyright field
$entry = $ifd->getEntry(PelTag::COPYRIGHT);

if ($entry == null)
{
        // No copyright field - make a new one
        $entry = new PelEntryCopyright($copyright);
        $ifd->addEntry($entry);
}
else
{
        // Overwrite existing field
        $entry->setValue($copyright);
}

// Save the updated file
$pel->saveFile($output_file);
于 2015-06-12T11:00:17.467 に答える