网站图片批量添加二维码,直接上代码
echo '=>start=>';
$sql = "SELECT * FROM " .$sse->table('mecine') . " where m_id between 18101 and 18408";//18408
$rows = $db->getAll($sql);
foreach($rows as $k => $row){
$photos = explode(',',$row['m_photos']);
$photoArr = [];
foreach($photos as $key => $photo){
//图片增加二维码,保留原来图片新增二维码图片
$img = getimagesize('../'.$photo);
$qrimg = getimagesize('./template/images/qrcode.jpg');
$top = $img[0] - $qrimg[0] - 20;//距离左上角距离x
$left = $img[1] - $qrimg[1] - 20;//距离左上角y
$pct = 100;//透明度
$imginfo = pathinfo($photo);
$qrdir = str_replace('photo','qr_photo','../'.$imginfo['dirname']);
if (!is_dir($qrdir)) {
is_dir($qrdir) or (mkdirs(dirname($qrdir)) and mkdir($qrdir,0777));
}
picMerge('../'.$photo,'./template/images/qrcode.jpg',$top,$left,$pct,str_replace('photo','qr_photo','../'.$photo));
$photoArr[] = str_replace('photo','qr_photo', $photo);
}
$photoStr = implode(',',$photoArr);
//处理主图
if($row['m_pic']){
$img = getimagesize('../'.$row['m_pic']);
$qrimg = getimagesize('./template/images/qrcode.jpg');
$top = $img[0] - $qrimg[0] - 20;//距离左上角距离x
$left = $img[1] - $qrimg[1] - 20;//距离左上角y
$pct = 100;//透明度
$imginfo = pathinfo($row['m_pic']);
$qrdir = str_replace('mecine','qr_mecine','../'.$imginfo['dirname']);
if (!is_dir($qrdir)) {
is_dir($qrdir) or (mkdirs(dirname($qrdir)) and mkdir($qrdir,0777));
}
picMerge('../'.$row['m_pic'],'./template/images/qrcode.jpg',$top,$left,$pct,str_replace('medicine','qr_mecine','../'.$row['m_pic']));
$m_pic = str_replace('mecine','qr_mecine',$row['m_pic']);//替换图片存储
}
//更新数据库
$sql = "update ".$GLOBALS['sse']->table('mecine')." set m_photos = '".$photoStr."',m_pic='".$m_pic."' where m_id = '".$row['m_id']."'";
$db->query($sql);
del_static_cache('get_mecine_info'.$row['m_id']);
echo '=>end=>'.$row['m_id'];