Using the setImageProperties() function, I attempted to write those properties to my image but for some reason it won't save the additions when I writeImage() to another JPG file. However, if I change it to a PNG file, the properties I set are saved. If I load the PNG file with the changes in tact and simply change it to a JPG, somehow the properties of the original JPG appear.
Here's the code I was trying which basically loads a jpg, displays the properties, adds a few properties, saves it to a png file then loads it and reads the properties:
Code: Select all
$im = new Imagick( 'images/file.jpg' );
$impng = $im->clone();
$impng_properties = $impng->getImageProperties();
foreach( $impng_properties as $key => $value ) {
echo $key . '=>' . $value . '<br />';
}
echo '<br />';
$impng->setImageProperty( "exif:Artist", "My Name" );
$impng->setImageProperty( "exif:Copyright", "Copyright, My Name, 2008. All rights reserved." );
$impng->setImageProperty( "exif:DateTime", date('Y:m:d H:i:s') );
$impng->setImageProperty( "exif:ImageDescription", "My PhotoSet" );
$impng->setImageProperty( "exif:UserComment", "Comment goes here" );
$impng->setImageFormat( 'png' );
$impng->writeImage( 'images/file.png' );
$impng->clear();
$impng->destroy();
$im2 = new Imagick( 'images/file.png' );
$imjpg = $im2->clone();
$imjpg_properties = $imjpg->getImageProperties();
foreach( $imjpg_properties as $key => $value ) {
echo $key . '=>' . $value . '<br />';
}
echo '<br />';
Code: Select all
$im = new Imagick( 'images/file.jpg' );
$impng = $im->clone();
$impng_properties = $impng->getImageProperties();
foreach( $impng_properties as $key => $value ) {
echo $key . '=>' . $value . '<br />';
}
echo '<br />';
$impng->setImageProperty( "exif:Artist", "My Name" );
$impng->setImageProperty( "exif:Copyright", "Copyright, My Name, 2008. All rights reserved." );
$impng->setImageProperty( "exif:DateTime", date('Y:m:d H:i:s') );
$impng->setImageProperty( "exif:ImageDescription", "My PhotoSet" );
$impng->setImageProperty( "exif:UserComment", "Comment goes here" );
$impng->setImageFormat( 'png' );
$impng->writeImage( 'images/file.png' );
$impng->clear();
$impng->destroy();
$im2 = new Imagick( 'images/file.png' );
$imjpg = $im2->clone();
$imjpg_properties = $imjpg->getImageProperties();
foreach( $imjpg_properties as $key => $value ) {
echo $key . '=>' . $value . '<br />';
}
echo '<br />';
$imjpg->setImageFormat( 'jpg' );
$imjpg->writeImage( 'images/file2.jpg' );
$imjpg->clear();
$imjpg->destroy();
$im3 = new Imagick( 'images/file2.jpg' );
$im2jpg = $im->clone();
$im2jpg_properties = $im2jpg->getImageProperties();
foreach( $im2jpg_properties as $key => $value ) {
echo $key . '=>' . $value . '<br />';
}
echo '<br />';