note 49411 deleted from ref.exif by nlopess
| From: | nlopess@php.net | Date: | Thu, 27 Jan 2005 11:06:08 +0000 |
| Subject: | note 49411 deleted from ref.exif by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-84068@lists.php.net to get a copy of this message | ||
Note Submitter: Otávio
----
#!/usr/bin/php
<?
/*
Copyright (C) 2005 - Otávio Corrêa Cordeiro
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
*/
function moveFile($fileName){
// Verifica o tipo do arquivo.
$fileType = mime_content_type($fileName);
if($fileType != "image/jpeg") return;
// Garante que o PHP possui o suporte a EXIF.
// O suporte é dado na compilação do PHP: --enable-exif
if(!extension_loaded(exif)) {
print "Please, check your PHP instalation/compilation.\n";
print "PHP should by compiled with --enable-exif option.\n";
return;
}
// Criar o EXIF da imagem e extrai a data da Fotografia
$exif = exif_read_data($fileName, 'EXIF');
$capture_data = $exif['DateTimeOriginal'];
// Reestrutura a string da data
$capture_data = str_replace(" ", ":", $capture_data);
$fileData = explode(":", $capture_data);
$fileData = $fileData[0]."-".$fileData[1]."-".$fileData[2];
if ($fileData == "--") return;
// Verifica se existe o diretório para a data da imagem
if(is_dir($fileData)){
// Em caso positivo, copia/move a imagem para ele.
print $fileName .": using directory ". $fileData ."\n";
if(copy($fileName, "$fileData/$fileName")) unlink($imagem);
} else {
// Senão, cria o diretório e copia/move a imagem para ele.
print $fileName .": creating directory ". $fileData ."\n";
mkdir($fileData);
if(copy($fileName, "$fileData/$fileName")) unlink($imagem);
}
}
if($argc == 1) {
// Mostra a ajuda.
print "Usage: ". $argv[0] ." file01.jpg file02.jpg ...\n";
} else {
// Faz o tratamento da string e executa a funcao
for($i=1; $i<$argc; $i++) {
$imagem = $argv[$i];
moveFile($imagem);
}
}
?>