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
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>
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!