<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Core\Util; use Intervention\Image\ImageManagerStatic as Image; use ModStart\Core\Exception\BizException; use ModStart\Core\Provider\FontProvider; class ImageUtil { public static function base64Src($Mb2Gw, $E1HRj = 'png') { if (!in_array($E1HRj, array('png', 'gif', 'jpg', 'jpeg'))) { return null; } return 'data:' . FileUtil::mime($E1HRj) . ';base64,' . base64_encode($Mb2Gw); } public static function limitSizeAndDetectOrientation($nAf_0, $hSXcF = 1000, $KpAin = 1000) { goto SK90F; Q3ORM: if (!in_array($DSBOq, $tiuIc)) { return; } goto nTLUG; nTLUG: try { goto ZCrP4; e1d2S: $ybneA = @exif_read_data($nAf_0); goto J8WE3; wLG5z: if ($n7Wq2) { $SwJYJ->save($nAf_0); } goto Qig3C; ZCrP4: $n7Wq2 = false; goto e1d2S; J8WE3: $SwJYJ = Image::make($nAf_0); goto Edt0k; EADjk: $SvdNO = $SwJYJ->height(); goto tlNfZ; tlNfZ: if ($GLdhF > $hSXcF || $SvdNO > $KpAin) { goto G0Et7; G0Et7: $n7Wq2 = true; goto Xz12s; Xz12s: if ($GLdhF > $hSXcF) { $SwJYJ->resize($hSXcF, intval($hSXcF * $SvdNO / $GLdhF)); } goto Y2D2_; Y2D2_: if ($SvdNO > $KpAin) { $SwJYJ->resize(intval($KpAin * $GLdhF / $SvdNO), $KpAin); } goto wMhoN; wMhoN: } goto wLG5z; Edt0k: if (!empty($ybneA['Orientation'])) { switch (intval($ybneA['Orientation'])) { case 2: goto NCo0I; bGqvH: break; goto l2phZ; NCo0I: $SwJYJ->flip(); goto ci94u; ci94u: $n7Wq2 = true; goto bGqvH; l2phZ: case 3: goto COkWj; xcHx3: break; goto zSJFa; uhY0F: $n7Wq2 = true; goto xcHx3; COkWj: $SwJYJ->rotate(180); goto uhY0F; zSJFa: case 4: goto PlK62; CEJKB: $SwJYJ->flip(); goto IEx3s; IEx3s: $n7Wq2 = true; goto JjINe; JjINe: break; goto hjjor; PlK62: $SwJYJ->rotate(180); goto CEJKB; hjjor: case 5: goto PlBSa; RZvwr: $n7Wq2 = true; goto rUQ2w; gnKA6: $SwJYJ->flip(); goto RZvwr; rUQ2w: break; goto y77nI; PlBSa: $SwJYJ->rotate(90); goto gnKA6; y77nI: case 6: goto LO_Fs; ilegv: $n7Wq2 = true; goto stiRT; LO_Fs: $SwJYJ->rotate(-90); goto ilegv; stiRT: break; goto lfoh2; lfoh2: case 7: goto qxP2q; e_zDW: $n7Wq2 = true; goto MMdOt; OABjy: $SwJYJ->flip(); goto e_zDW; qxP2q: $SwJYJ->rotate(90); goto OABjy; MMdOt: break; goto tILzL; tILzL: case 8: goto nnRUQ; nnRUQ: $SwJYJ->rotate(90); goto Oat1Q; Oat1Q: $n7Wq2 = true; goto jyDM0; jyDM0: break; goto vwJWK; vwJWK: } } goto uD9E3; uD9E3: $GLdhF = $SwJYJ->width(); goto EADjk; Qig3C: } catch (\Exception $SwVsw) { throw $SwVsw; } goto mmKs6; SK90F: $tiuIc = array('jpg', 'jpeg', 'png', 'gif'); goto R0w9P; R0w9P: $DSBOq = FileUtil::extension($nAf_0); goto Q3ORM; mmKs6: } public static function watermark($SwJYJ, $E1HRj, $BWI89, $nZw7W = array()) { goto Tzxgk; RCD6X: $GLdhF = $KuawA->width(); goto S2Kco; gJRRK: if ($n7Wq2) { $KuawA->save($SwJYJ); } goto XEiQT; gsCgj: if (empty($nZw7W['position'])) { $nZw7W['position'] = 'bottom-right'; } goto G4rtl; S2Kco: $SvdNO = $KuawA->height(); goto ENwBs; vftMB: if (!isset($nZw7W['return'])) { $nZw7W['return'] = false; } goto gsCgj; tW_5s: switch ($E1HRj) { case 'text': goto xQ_3z; xQ_3z: if (empty($BWI89)) { return; } goto hvkqE; Wtf_r: $n7Wq2 = true; goto iWGDp; iWGDp: break; goto wSsCT; hvkqE: $KuawA->text($BWI89, $GLdhF - $d1y5y, $SvdNO - $d1y5y, function ($AbM3l) use($GLdhF, $SvdNO) { $mFST1 = max(min($GLdhF, $SvdNO) / 30, 10); $AbM3l->file(FontProvider::firstLocalPathOrFail()); $AbM3l->size($mFST1); $AbM3l->color('rgba(255, 255, 255, 0.5)'); $AbM3l->align('right'); $AbM3l->valign('bottom'); }); goto Wtf_r; wSsCT: case 'image': goto dx1zy; n5w0h: $n7Wq2 = true; goto Hch97; T_Ubn: if (empty($JBz2U) || !file_exists($JBz2U)) { return; } goto Vtgig; jiAtA: $QbZXa->opacity(50); goto Q7bjs; zuO_q: $QbZXa->resize($vLGuZ, $VKyiR); goto jiAtA; Vtgig: $QbZXa = Image::make($JBz2U); goto Hm0z6; dx1zy: $JBz2U = FileUtil::savePathToLocalTemp($BWI89); goto T_Ubn; Q7bjs: $KuawA->insert($QbZXa, $nZw7W['position'], $d1y5y, $d1y5y); goto n5w0h; Hch97: break; goto xV3bB; Hm0z6: $D8igw = max(min($GLdhF, $SvdNO) / 10, 10); goto MVIdf; aGZH4: $VKyiR = $QbZXa->height(); goto KL7uf; KL7uf: if ($vLGuZ > $VKyiR) { $VKyiR = intval($D8igw * $VKyiR / $vLGuZ); $vLGuZ = $D8igw; } else { $vLGuZ = intval($D8igw * $vLGuZ / $VKyiR); $VKyiR = $D8igw; } goto zuO_q; MVIdf: $vLGuZ = $QbZXa->width(); goto aGZH4; xV3bB: } goto t4oAu; yvCz9: $n7Wq2 = false; goto QIQlF; Wl1FX: $d1y5y = intval(min($GLdhF, $SvdNO) / 50); goto tW_5s; Tzxgk: switch ($E1HRj) { case 'text': case 'image': break; default: BizException::throws('Unknown watermark type'); } goto vftMB; G4rtl: BizException::throwsIf('Unknown water position', !in_array($nZw7W['position'], array('center', 'bottom-right', 'top-right', 'bottom-left', 'top-left', 'left', 'right', 'top', 'bottom'))); goto yvCz9; t4oAu: if ($nZw7W['return']) { return $KuawA->response('png'); } goto gJRRK; QIQlF: $KuawA = Image::make($SwJYJ); goto RCD6X; ENwBs: if ($GLdhF < 100 || $SvdNO < 100) { return; } goto Wl1FX; XEiQT: } public static function info($Jtt5u) { $KuawA = Image::make($Jtt5u); return array('width' => $KuawA->width(), 'height' => $KuawA->height(), 'size' => $KuawA->filesize()); } }