Hướng dẫn php add metadata to image - php thêm siêu dữ liệu vào hình ảnh

Có cách nào để thêm siêu dữ liệu (chẳng hạn như từ khóa) vào một số hình ảnh PNG bằng PHP không? Tôi đã lưu trữ các hình ảnh trong cơ sở dữ liệu của mình và tôi muốn làm tương tự với các từ khóa tương ứng của chúng, nhưng tôi chưa tìm thấy bất kỳ đề xuất hữu ích nào khi sử dụng PHP. Cảm ơn

image.php




	Upload Images

 
	

Select Image (one or multiple):

Tags.php (câu trả lời của Raptor)

readImage("C:/xampp/htdocs/cmanager/uploads");
$image->setImageProperty('keywords', 'Imagick');

print($image->getImageProperty('keywords'));

Đã hỏi ngày 10 tháng 3 năm 2016 lúc 10:01Mar 10, 2016 at 10:01

Hướng dẫn php add metadata to image - php thêm siêu dữ liệu vào hình ảnh

Joasajoasajoasa

8944 Huy hiệu vàng15 Huy hiệu bạc32 Huy hiệu đồng4 gold badges15 silver badges32 bronze badges

Bạn cần sự giúp đỡ của SetImageProperty () của ImageMagick để đạt được mục tiêu của bạn.

newImage(300, 200, "black"); // or load your PNG into Imagick

$image->setImageProperty('keywords', 'Imagick');
echo $image->getImageProperty('keywords');
?>

Yêu cầu PHP để biên dịch với Imagemagick 6.3.2+.

Ngoài ra, bạn có thể phân tích siêu dữ liệu của PNG với các mã được hiển thị ở đây. Thử nó ra.

Cuối cùng, nếu bạn có ý định chỉnh sửa dữ liệu EXIF, bạn có thể sử dụng các chức năng EXIF.

Đã trả lời ngày 10 tháng 3 năm 2016 lúc 10:10Mar 10, 2016 at 10:10

Hướng dẫn php add metadata to image - php thêm siêu dữ liệu vào hình ảnh

RaptorraptorRaptor

52K44 Huy hiệu vàng222 Huy hiệu bạc356 Huy hiệu Đồng44 gold badges222 silver badges356 bronze badges

11

Hướng dẫn php add metadata to image - php thêm siêu dữ liệu vào hình ảnh

Hướng dẫn php add metadata to image - php thêm siêu dữ liệu vào hình ảnh

Hãy tưởng tượng 0,6 đi kèm với một sự trừu tượng để đọc siêu dữ liệu hình ảnh.

Truy cập siêu dữ liệu hình ảnh

Siêu dữ liệu được đọc với

readImage("C:/xampp/htdocs/cmanager/uploads");
$image->setImageProperty('keywords', 'Imagick');

print($image->getImageProperty('keywords'));
0 và có thể truy cập thông qua phương thức
readImage("C:/xampp/htdocs/cmanager/uploads");
$image->setImageProperty('keywords', 'Imagick');

print($image->getImageProperty('keywords'));
1 trả về đối tượng
readImage("C:/xampp/htdocs/cmanager/uploads");
$image->setImageProperty('keywords', 'Imagick');

print($image->getImageProperty('keywords'));
2:



use Imagine\Image\Metadata\ExifMetadataReader;

$image = $imagine->open('/path/to/image.jpg');
$metadata = $image->metadata();

// prints '/path/to/image.jpg'
print($metadata['filename']);

Thay đổi đầu đọc siêu dữ liệu

Hãy tưởng tượng đi kèm với hai độc giả siêu dữ liệu:

readImage("C:/xampp/htdocs/cmanager/uploads");
$image->setImageProperty('keywords', 'Imagick');

print($image->getImageProperty('keywords'));
3 và
readImage("C:/xampp/htdocs/cmanager/uploads");
$image->setImageProperty('keywords', 'Imagick');

print($image->getImageProperty('keywords'));
4.

Tưởng tượng sử dụng đầu đọc siêu dữ liệu mặc định theo mặc định. Bạn có thể dễ dàng chuyển sang phương thức bạn muốn sử dụng phương thức

readImage("C:/xampp/htdocs/cmanager/uploads");
$image->setImageProperty('keywords', 'Imagick');

print($image->getImageProperty('keywords'));
5.



use Imagine\Image\Metadata\ExifMetadataReader;

$imagine->setMetadataReader(new ExifMetadataReader());

Đầu đọc siêu dữ liệu mặc định

Đầu đọc siêu dữ liệu mặc định là một trình đọc cơ bản lưu trữ thông tin ban đầu về tài nguyên.



use Imagine\Image\Metadata\DefaultMetadataReader;

$image = $imagine
    ->setMetadataReader(new DefaultMetadataReader())
    ->open('chenille.jpg');
$metadata = $image->metadata();

var_dump($metadata->toArray());

Mã trước đó có thể tạo ra đầu ra như vậy:

array(2) {
  'filepath' =>
  string(60) "/Users/romainneutron/Documents/workspace/Imagine/chenille.jpg"
  'uri' =>
  string(12) "chenille.jpg"
}

Trình đọc siêu dữ liệu Exif

Trình đọc siêu dữ liệu EXIF ​​cung cấp thông tin cơ bản giống như đầu đọc siêu dữ liệu mặc định và thêm dữ liệu EXIF ​​do tiện ích mở rộng EXIF ​​cung cấp.

Ghi chú

Sử dụng đầu đọc siêu dữ liệu EXIF ​​thêm một chi phí quan trọng để xử lý hình ảnh.



use Imagine\Image\Metadata\ExifMetadataReader;

$image = $imagine
    ->setMetadataReader(new ExifMetadataReader())
    ->open('chenille.jpg');
$metadata = $image->metadata();

var_dump($metadata->toArray());

Mã trước sẽ tạo ra đầu ra này:

array(37) {
  'filepath' =>
  string(60) "/Users/romainneutron/Documents/workspace/Imagine/chenille.jpg"
  'uri' =>
  string(12) "chenille.jpg"
  'exif.ExposureTime' =>
  string(5) "1/120"
  'exif.FNumber' =>
  string(4) "11/5"
  'exif.ExposureProgram' =>
  int(2)
  'exif.ISOSpeedRatings' =>
  int(40)
  'exif.ExifVersion' =>
  string(4) "0221"
  'exif.DateTimeOriginal' =>
  string(19) "2014:04:06 16:11:59"
  'exif.DateTimeDigitized' =>
  string(19) "2014:04:06 16:11:59"
  'exif.ComponentsConfiguration' =>
  string(4) "\000"
  'exif.ShutterSpeedValue' =>
  string(9) "9488/1373"
  'exif.ApertureValue' =>
  string(9) "7801/3429"
  'exif.BrightnessValue' =>
  string(8) "4457/710"
  'exif.MeteringMode' =>
  int(3)
  'exif.Flash' =>
  int(16)
  'exif.FocalLength' =>
  string(6) "103/25"
  'exif.ColorSpace' =>
  int(1)
  'exif.ExifImageWidth' =>
  int(2048)
  'exif.ExifImageLength' =>
  int(1536)
  'exif.SensingMethod' =>
  int(2)
  'exif.ExposureMode' =>
  int(0)
  'exif.WhiteBalance' =>
  int(0)
  'exif.FocalLengthIn35mmFilm' =>
  int(30)
  'exif.SceneCaptureType' =>
  int(0)
  'exif.UndefinedTag:0xA433' =>
  string(5) "Apple"
  'exif.UndefinedTag:0xA434' =>
  string(34) "iPhone 5s back camera 4.12mm f/2.2"
  'ifd0.Make' =>
  string(5) "Apple"
  'ifd0.Model' =>
  string(9) "iPhone 5s"
  'ifd0.XResolution' =>
  string(4) "72/1"
  'ifd0.YResolution' =>
  string(4) "72/1"
  'ifd0.ResolutionUnit' =>
  int(2)
  'ifd0.Software' =>
  string(5) "7.0.4"
  'ifd0.DateTime' =>
  string(19) "2014:04:06 16:11:59"
  'ifd0.YCbCrPositioning' =>
  int(1)
  'ifd0.Exif_IFD_Pointer' =>
  int(192)
  'ifd0.GPS_IFD_Pointer' =>
  int(1486)
}

Tạo đầu đọc siêu dữ liệu của riêng bạn

Bất kỳ người đọc siêu dữ liệu nào cũng phải thực hiện

readImage("C:/xampp/htdocs/cmanager/uploads");
$image->setImageProperty('keywords', 'Imagick');

print($image->getImageProperty('keywords'));
0. Tuy nhiên, nó dễ dàng hơn để mở rộng
readImage("C:/xampp/htdocs/cmanager/uploads");
$image->setImageProperty('keywords', 'Imagick');

print($image->getImageProperty('keywords'));
7 để tránh những thứ còn thiếu và tập trung vào mục đích của người đọc.

Dưới đây, một ví dụ về đầu đọc siêu dữ liệu lấy thông tin truy cập POSIX từ một tệp:



use Imagine\Image\Metadata\AbstractMetadataReader;

class PosixMetadataReader extends AbstractMetadataReader
{
    /**
     * {@inheritdoc}
     */
    protected function extractFromFile($file)
    {
        // if file is not local, forget it
        if (!stream_is_local($file)) {
            return array();
        }

        return array(
            'access' => posix_access($file),
        );
    }

    /**
     * {@inheritdoc}
     */
    protected function extractFromData($data)
    {
        // posix informations about raw data in non-sense
        return array();
    }

    /**
     * {@inheritdoc}
     */
    protected function extractFromStream($resource)
    {
        if (!stream_is_local($file)) {
            return array();
        }

        if (false !== $data = @stream_get_meta_data($resource)) {
            return array(
                'access' => posix_access($data['uri']),
            );
        }

        return array();
    }
}

Nhận xét được cung cấp bởi DisqusDisqus

Làm cách nào để thêm siêu dữ liệu vào hình ảnh?

Nhấp chuột phải vào hình ảnh và chọn các thuộc tính trên mạng.
Trong cửa sổ xuất hiện, bạn có thể thay đổi tên tệp, thêm thẻ, viết mô tả, v.v.

Tôi có thể thêm siêu dữ liệu vào JPEG không?

Mở thư mục trên máy tính của bạn có chứa tệp hình ảnh hoặc video.Người dùng PC: Nhấp chuột phải vào hình ảnh và chọn Thuộc tính.MAC Người dùng: Nhấp chuột kiểm soát và chọn Nhận thông tin (hoặc nhấn lệnh + I trên bàn phím của bạn).Trong cửa sổ xuất hiện, bạn có thể thay đổi tên, thêm thẻ, viết mô tả và hơn thế nữa.PC users: Right-click on the image, and select Properties. Mac users: Control-click, and select Get Info (or press command + i on your keyboard). In the window that appears, you can change the name, add tags, write a description, and more.

Siêu dữ liệu ở đâu trong JPEG?

Cách truy cập và xem siêu dữ liệu ảnh..
Xác định vị trí và nhấp chuột phải vào tệp hình ảnh kỹ thuật số dự định ..
Chọn 'Thuộc tính'.
Nhấp vào tab 'Chi tiết' ở đầu cửa sổ bật lên ..
Bây giờ chỉ cần cuộn xuống qua cửa sổ kết quả cho đến khi bạn tìm thấy phần siêu dữ liệu bạn yêu cầu ..

Siêu dữ liệu nào được lưu trữ với một tệp hình ảnh?

Nó bao gồm các chi tiết camera và cài đặt như khẩu độ, tốc độ màn trập, số ISO, độ sâu tiêu cự, chấm trên mỗi inch (DPI).Các siêu dữ liệu được tạo tự động khác bao gồm thương hiệu và mô hình camera, ngày và giờ khi hình ảnh được tạo và vị trí GPS nơi nó được tạo.camera details and settings such as aperture, shutter speed, ISO number, focal depth, dots per inch (DPI). Other automatically generated metadata include the camera brand and model, the date and time when the image was created and the GPS location where it was created.