<?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($jdL9Y, $pW0Nz = 'png') { if (!in_array($pW0Nz, array('png', 'gif', 'jpg', 'jpeg'))) { return null; } return 'data:' . FileUtil::mime($pW0Nz) . ';base64,' . base64_encode($jdL9Y); } public static function limitSizeAndDetectOrientation($YhsOb, $kqBdk = 1000, $kDaPc = 1000) { goto Y_Iy6; PEY87: if (!in_array($tZ9zg, $B0jq3)) { return; } goto YVumw; YVumw: try { goto D3op4; GzXgQ: $ek5zd = @exif_read_data($YhsOb); goto iW68e; DJ_GU: if (!empty($ek5zd['Orientation'])) { switch (intval($ek5zd['Orientation'])) { case 2: goto rN7is; MQaca: $ngFQ7 = true; goto UXc1e; UXc1e: break; goto fkPsz; rN7is: $GKjmh->flip(); goto MQaca; fkPsz: case 3: goto rrEAa; HvC6o: break; goto Czbkm; vgSPl: $ngFQ7 = true; goto HvC6o; rrEAa: $GKjmh->rotate(180); goto vgSPl; Czbkm: case 4: goto KIrER; YEv6N: $GKjmh->flip(); goto GWufx; gRQhD: break; goto a77S6; GWufx: $ngFQ7 = true; goto gRQhD; KIrER: $GKjmh->rotate(180); goto YEv6N; a77S6: case 5: goto AuoY0; AuoY0: $GKjmh->rotate(90); goto byrDx; DzWBq: break; goto CUW2I; byrDx: $GKjmh->flip(); goto Fohfj; Fohfj: $ngFQ7 = true; goto DzWBq; CUW2I: case 6: goto ieQEl; YVSTv: $ngFQ7 = true; goto fYFEq; fYFEq: break; goto EhKDi; ieQEl: $GKjmh->rotate(-90); goto YVSTv; EhKDi: case 7: goto qk8oP; GNnEB: $ngFQ7 = true; goto gOYMm; qk8oP: $GKjmh->rotate(90); goto uqscw; uqscw: $GKjmh->flip(); goto GNnEB; gOYMm: break; goto avdUM; avdUM: case 8: goto ARPXN; X8qWf: $ngFQ7 = true; goto oGdO0; oGdO0: break; goto qi86H; ARPXN: $GKjmh->rotate(90); goto X8qWf; qi86H: } } goto dMczM; dMczM: $pbpff = $GKjmh->width(); goto De5Tk; De5Tk: $jfslc = $GKjmh->height(); goto VRxBM; e3dtF: if ($ngFQ7) { $GKjmh->save($YhsOb); } goto a5daM; D3op4: $ngFQ7 = false; goto GzXgQ; VRxBM: if ($pbpff > $kqBdk || $jfslc > $kDaPc) { goto a8iCU; caTGj: if ($jfslc > $kDaPc) { $GKjmh->resize(intval($kDaPc * $pbpff / $jfslc), $kDaPc); } goto DaJCf; a8iCU: $ngFQ7 = true; goto juaEG; juaEG: if ($pbpff > $kqBdk) { $GKjmh->resize($kqBdk, intval($kqBdk * $jfslc / $pbpff)); } goto caTGj; DaJCf: } goto e3dtF; iW68e: $GKjmh = Image::make($YhsOb); goto DJ_GU; a5daM: } catch (\Exception $Xlb8r) { throw $Xlb8r; } goto VSKO_; l9fG4: $tZ9zg = FileUtil::extension($YhsOb); goto PEY87; Y_Iy6: $B0jq3 = array('jpg', 'jpeg', 'png', 'gif'); goto l9fG4; VSKO_: } public static function watermark($GKjmh, $pW0Nz, $vVYCS, $Ggr9v = array()) { goto vnFlM; gZR85: $jfslc = $M2ENb->height(); goto Dk5f2; yYKd9: if ($ngFQ7) { $M2ENb->save($GKjmh); } goto wiDmo; Dk5f2: if ($pbpff < 100 || $jfslc < 100) { return; } goto YFte4; ssy56: if (!isset($Ggr9v['return'])) { $Ggr9v['return'] = false; } goto NYeIo; YFte4: $Xc9Pp = intval(min($pbpff, $jfslc) / 50); goto IAGXE; IzqL1: $ngFQ7 = false; goto oeFEF; NYeIo: if (empty($Ggr9v['position'])) { $Ggr9v['position'] = 'bottom-right'; } goto bS_Iz; TKrRB: $pbpff = $M2ENb->width(); goto gZR85; vnFlM: switch ($pW0Nz) { case 'text': case 'image': break; default: BizException::throws('Unknown watermark type'); } goto ssy56; lnRaX: if ($Ggr9v['return']) { return $M2ENb->response('png'); } goto yYKd9; oeFEF: $M2ENb = Image::make($GKjmh); goto TKrRB; IAGXE: switch ($pW0Nz) { case 'text': goto to00R; EGH93: $ngFQ7 = true; goto G2UYl; G2UYl: break; goto W5qDv; to00R: if (empty($vVYCS)) { return; } goto TBAxt; TBAxt: $M2ENb->text($vVYCS, $pbpff - $Xc9Pp, $jfslc - $Xc9Pp, function ($pK7Ts) use($pbpff, $jfslc) { $DLS9l = max(min($pbpff, $jfslc) / 30, 10); $pK7Ts->file(FontProvider::firstLocalPathOrFail()); $pK7Ts->size($DLS9l); $pK7Ts->color('rgba(255, 255, 255, 0.5)'); $pK7Ts->align('right'); $pK7Ts->valign('bottom'); }); goto EGH93; W5qDv: case 'image': goto x6Guz; WTV6i: $JAcjY = max(min($pbpff, $jfslc) / 10, 10); goto WXyQv; RHHE0: $M2ENb->insert($dqmZH, $Ggr9v['position'], $Xc9Pp, $Xc9Pp); goto oiKxm; x6Guz: $fx9_S = FileUtil::savePathToLocalTemp($vVYCS); goto Nl7NG; oiKxm: $ngFQ7 = true; goto Lb_jZ; rnDzZ: $dqmZH->opacity(50); goto RHHE0; zEXoy: $dqmZH = Image::make($fx9_S); goto WTV6i; gOR6Y: $dqmZH->resize($sBivg, $SqD08); goto rnDzZ; zVk22: if ($sBivg > $SqD08) { $SqD08 = intval($JAcjY * $SqD08 / $sBivg); $sBivg = $JAcjY; } else { $sBivg = intval($JAcjY * $sBivg / $SqD08); $SqD08 = $JAcjY; } goto gOR6Y; WXyQv: $sBivg = $dqmZH->width(); goto mPAbz; Lb_jZ: break; goto s2I4S; Nl7NG: if (empty($fx9_S) || !file_exists($fx9_S)) { return; } goto zEXoy; mPAbz: $SqD08 = $dqmZH->height(); goto zVk22; s2I4S: } goto lnRaX; bS_Iz: BizException::throwsIf('Unknown water position', !in_array($Ggr9v['position'], array('center', 'bottom-right', 'top-right', 'bottom-left', 'top-left', 'left', 'right', 'top', 'bottom'))); goto IzqL1; wiDmo: } public static function info($ypGny) { $M2ENb = Image::make($ypGny); return array('width' => $M2ENb->width(), 'height' => $M2ENb->height(), 'size' => $M2ENb->filesize()); } }