<?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($Zt525, $F28aA = 'png') { if (!in_array($F28aA, array('png', 'gif', 'jpg', 'jpeg'))) { return null; } return 'data:' . FileUtil::mime($F28aA) . ';base64,' . base64_encode($Zt525); } public static function limitSizeAndDetectOrientation($adFNb, $ztfs_ = 1000, $yB1ib = 1000) { goto uStFZ; uStFZ: $i7Bhy = array('jpg', 'jpeg', 'png', 'gif'); goto Vpo_B; wTC8E: if (!in_array($XOpZz, $i7Bhy)) { return; } goto nWT_p; nWT_p: try { goto nLJCG; cd1Yl: $Mn0B7 = @exif_read_data($adFNb); goto DUzIW; PrDvQ: if ($K23VU) { $wduBe->save($adFNb); } goto N5kLD; BDmCT: if (!empty($Mn0B7['Orientation'])) { switch (intval($Mn0B7['Orientation'])) { case 2: goto ZFViZ; Lu_vg: break; goto l1YUg; ZFViZ: $wduBe->flip(); goto oUpGE; oUpGE: $K23VU = true; goto Lu_vg; l1YUg: case 3: goto u6TML; u6TML: $wduBe->rotate(180); goto yTsl_; yTsl_: $K23VU = true; goto ih3q8; ih3q8: break; goto pQ6W3; pQ6W3: case 4: goto CzoqR; wjFKg: break; goto muFyV; CzoqR: $wduBe->rotate(180); goto w0nni; w0nni: $wduBe->flip(); goto GGQTL; GGQTL: $K23VU = true; goto wjFKg; muFyV: case 5: goto sX7GB; k6z50: break; goto YnFcX; sX7GB: $wduBe->rotate(90); goto YkUqr; YkUqr: $wduBe->flip(); goto PEaVZ; PEaVZ: $K23VU = true; goto k6z50; YnFcX: case 6: goto DAgm6; DAgm6: $wduBe->rotate(-90); goto Ixcey; Ixcey: $K23VU = true; goto YTDI8; YTDI8: break; goto w5cRf; w5cRf: case 7: goto RSC4f; RSC4f: $wduBe->rotate(90); goto Iyvuc; FpGr9: break; goto bixqd; MMF78: $K23VU = true; goto FpGr9; Iyvuc: $wduBe->flip(); goto MMF78; bixqd: case 8: goto VNPPm; pT5an: break; goto LDvgq; VNPPm: $wduBe->rotate(90); goto EzLQl; EzLQl: $K23VU = true; goto pT5an; LDvgq: } } goto f8CE0; nLJCG: $K23VU = false; goto cd1Yl; DUzIW: $wduBe = Image::make($adFNb); goto BDmCT; MFkL6: if ($jy3JI > $ztfs_ || $ny2Lp > $yB1ib) { goto poxJ2; fnOH7: if ($jy3JI > $ztfs_) { $wduBe->resize($ztfs_, intval($ztfs_ * $ny2Lp / $jy3JI)); } goto LVVDp; poxJ2: $K23VU = true; goto fnOH7; LVVDp: if ($ny2Lp > $yB1ib) { $wduBe->resize(intval($yB1ib * $jy3JI / $ny2Lp), $yB1ib); } goto YFyfF; YFyfF: } goto PrDvQ; f8CE0: $jy3JI = $wduBe->width(); goto oEoAh; oEoAh: $ny2Lp = $wduBe->height(); goto MFkL6; N5kLD: } catch (\Exception $tZVhb) { throw $tZVhb; } goto Z2iW6; Vpo_B: $XOpZz = FileUtil::extension($adFNb); goto wTC8E; Z2iW6: } public static function watermark($wduBe, $F28aA, $LTC5O, $Ur1_b = array()) { goto JEl9A; vbliN: if (!isset($Ur1_b['return'])) { $Ur1_b['return'] = false; } goto SM9k2; SM9k2: if (empty($Ur1_b['position'])) { $Ur1_b['position'] = 'bottom-right'; } goto s9hgl; ujS8u: if ($K23VU) { $yG7Yd->save($wduBe); } goto O7WzI; ZojKE: $K23VU = false; goto wpmHw; JEl9A: switch ($F28aA) { case 'text': case 'image': break; default: BizException::throws('Unknown watermark type'); } goto vbliN; vj73A: $KwEBz = intval(min($jy3JI, $ny2Lp) / 50); goto qt7HI; qt7HI: switch ($F28aA) { case 'text': goto aCNIV; oZ1CO: $yG7Yd->text($LTC5O, $jy3JI - $KwEBz, $ny2Lp - $KwEBz, function ($yhLwl) use($jy3JI, $ny2Lp) { $Xjpmm = max(min($jy3JI, $ny2Lp) / 30, 10); $yhLwl->file(FontProvider::firstLocalPathOrFail()); $yhLwl->size($Xjpmm); $yhLwl->color('rgba(255, 255, 255, 0.5)'); $yhLwl->align('right'); $yhLwl->valign('bottom'); }); goto WJBZ4; WJBZ4: $K23VU = true; goto m045e; m045e: break; goto GDJ_Y; aCNIV: if (empty($LTC5O)) { return; } goto oZ1CO; GDJ_Y: case 'image': goto OYDhQ; BRfql: $kPLS6->opacity(50); goto Ve4qO; oM20m: $K23VU = true; goto tR6cj; bt1_4: if ($MoKRR > $xWDpo) { $xWDpo = intval($XzVT3 * $xWDpo / $MoKRR); $MoKRR = $XzVT3; } else { $MoKRR = intval($XzVT3 * $MoKRR / $xWDpo); $xWDpo = $XzVT3; } goto w5Vds; fpfSr: $xWDpo = $kPLS6->height(); goto bt1_4; ySwhj: $MoKRR = $kPLS6->width(); goto fpfSr; tR6cj: break; goto fEtXo; OYDhQ: $D3Pw7 = FileUtil::savePathToLocalTemp($LTC5O); goto vD0BI; Ve4qO: $yG7Yd->insert($kPLS6, $Ur1_b['position'], $KwEBz, $KwEBz); goto oM20m; w5Vds: $kPLS6->resize($MoKRR, $xWDpo); goto BRfql; OOmzS: $kPLS6 = Image::make($D3Pw7); goto WD85T; vD0BI: if (empty($D3Pw7) || !file_exists($D3Pw7)) { return; } goto OOmzS; WD85T: $XzVT3 = max(min($jy3JI, $ny2Lp) / 10, 10); goto ySwhj; fEtXo: } goto h33Bp; eZQ9T: $ny2Lp = $yG7Yd->height(); goto UO2VU; XWiJh: $jy3JI = $yG7Yd->width(); goto eZQ9T; h33Bp: if ($Ur1_b['return']) { return $yG7Yd->response('png'); } goto ujS8u; UO2VU: if ($jy3JI < 100 || $ny2Lp < 100) { return; } goto vj73A; wpmHw: $yG7Yd = Image::make($wduBe); goto XWiJh; s9hgl: BizException::throwsIf('Unknown water position', !in_array($Ur1_b['position'], array('center', 'bottom-right', 'top-right', 'bottom-left', 'top-left', 'left', 'right', 'top', 'bottom'))); goto ZojKE; O7WzI: } public static function info($sCmIC) { $yG7Yd = Image::make($sCmIC); return array('width' => $yG7Yd->width(), 'height' => $yG7Yd->height(), 'size' => $yG7Yd->filesize()); } }