防止对图片多次打水印,因此对水印图片增加了标识符!
/**
* 设置水印标识符
*
* @param type $fileName
* @param type $flag
* return void
*/
function setWaterFlag($fileName,$flag = 'easymro')
{
if(!file_exists($fileName)) throw new Exception ('not found file when setWaterFlag!');
$handle = fopen($fileName, 'a+b');
flock($handle, LOCK_EX);
if(!is_writable($fileName)) throw new Exception('this file cant writable!');
if(fwrite($handle,$flag) === false) throw new Exception('writable falid!');
fclose ($handle);
}
/**
* 检查是否添加过水印
*
* @param type $fileName
* @param string $flag default easymro 水印识别符
* @return bool
*/
function isSetWaterFlag($fileName,$flag = 'easymro')
{
if(!file_exists($fileName)) throw new Exception ('not found file when isSetWaterFlag!');
$handle = fopen($fileName, 'rb');;
$stream = fread($handle, filesize($fileName));
if(strpos($stream, $flag) === false) return false;
fclose($handle);
return true;
}