How to Insert Exif Data into Images Using Linux or PHP?

Mary-Kate Olsen
Release: 2024-10-21 14:58:30
Original
694 people have browsed it

How to Insert Exif Data into Images Using Linux or PHP?

Adding Exif Data to Images with ImageMagick

In various scenarios, it becomes necessary to add missing or remove unwanted exif data from images. Exif data holds essential information about the image, such as camera settings, copyright, and location. However, to optimize image file sizes, exif data is often removed.

To insert basic exif data back into an image after stripping it using ImageMagick's mogrify command, you can utilize the exiftool utility.

Exiftool for Exif Data Manipulation

Exiftool offers a powerful command-line interface for manipulating exif data. You can add, remove, and edit exif tags with ease. To install Exiftool on your system, refer to the official documentation.

To insert the desired exif data into your image, execute the following command:

exiftool -copyright="Initrode Copyright" image.jpg
Copy after login

Replace "Initrode Copyright" with the desired copyright information. You can add additional exif tags in a similar manner, as per the Exiftool documentation.

Alternative PHP Solution

While Exiftool is a comprehensive tool for handling exif data, if you prefer a PHP-based solution, you can use the following PHP script:

<code class="php"><?php

$image = 'image.jpg';
$exif = array(
    'Copyright' => 'Initrode Copyright',
    // Add other exif tags here...
);

// Create a new image with desired exif data
imagejpeg(imagecreatefromjpeg($image), $image, 100);

exif_read_data($image);
foreach ($exif as $key => $value) {
    exif_set_tag($image, $key, $value);
}

exif_save_data($image);

?></code>
Copy after login

Replace the image.jpg filename and provide the exif tags as needed. This script will overwrite the existing exif data with the specified values.

The above is the detailed content of How to Insert Exif Data into Images Using Linux or PHP?. For more information, please follow other related articles on the PHP Chinese website!

source:php
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!