LoginSignup
21
22

More than 5 years have passed since last update.

GDまたはImagick拡張でexif情報を削除する

Posted at

GDだとCOMMENTセクションが勝手につく。

exif1.php
<?php

$gd = imagecreatefromjpeg( "in.jpg" );
$w = imagesx( $gd );
$h = imagesy( $gd );
$gd_out = imagecreatetruecolor( $w, $h );
imagecopyresampled( $gd_out, $gd, 0,0,0,0, $w,$h,$w,$h );
imagejpeg( $gd_out, "out.jpg" );
imagedestroy( $gd );

print_r( exif_read_data( "out.jpg" ) );
// exifにCOMMENTが勝手につく
// [COMMENT] => Array
// (
//  [0] => CREATOR: gd-jpeg v1.0 (using IJG JPEG v80), default quality
// )

Imagick拡張使えば何も残らない。

exif2.php
<?php

$im = new \Imagick( "in.jpg" );
$im->stripImage();
$im->writeImage( "out.jpg" );
$im->destroy();

print_r( exif_read_data( "out.jpg" ) );
// exif情報全部消える
21
22
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
21
22