src/Troika/MainBundle/Helper/ImageHelper.php line 18

Open in your IDE?
  1. <?php
  2. namespace Troika\MainBundle\Helper;
  3. use Imagick;
  4. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  5. class ImageHelper
  6. {
  7.     public const ImagickCOLOR_OPACITY 18;
  8.     public static function preview($img$widthO 285$heightO 180$name)
  9.     {
  10.         try {
  11.             $imgFile $_SERVER['DOCUMENT_ROOT'] . $img;
  12.             $imageSize = @getimagesize($imgFile);
  13.             if (!is_array($imageSize)) {
  14.                 throw new NotFoundHttpException('Файл изображения не найден');
  15.             }
  16.             $image = new Imagick($imgFile);
  17.             $height $image->getImageHeight();
  18.             $width $image->getImageWidth();
  19.             if ($width $height) {
  20.                 $ratio $widthO $heightO $width $height;
  21.                 if ($ratio 0) {
  22.                     $heightRatio $height $width $heightO $widthO;
  23.                     $image->cropImage($width$height $heightRatio0, ($heightRatio 2));
  24.                 } else {
  25.                     $widthRatio $width $height $widthO $heightO;
  26.                     $image->cropImage($width $widthRatio$height, ($widthRatio 2), 0);
  27.                 }
  28.                 $image->resizeImage($widthO$heightOself::ImagickCOLOR_OPACITYtrue);
  29.                 $thumbnail $image->getImageBlob();
  30.             } else {
  31.                 $nWidth $width * ($heightO $height);
  32.                 $image->resizeImage(
  33.                   (int)($width * ($heightO $height)),
  34.                   (int)$heightO,
  35.                   self::ImagickCOLOR_OPACITY,
  36.                   true
  37.                 ); //Imagick::COLOR_OPACITY
  38.                 $imagePod = new Imagick();
  39.                 $imagePod->newImage($widthO$heightO, new \ImagickPixel('transparent'));
  40.                 $imagePod->setImageFormat('png');
  41.                 $imagePod->setImageVirtualPixelMethod(\Imagick::VIRTUALPIXELMETHOD_TRANSPARENT);
  42.                 $imagePod->compositeImage($image, \Imagick::COMPOSITE_PLUS, ($widthO $nWidth) / 20);
  43.                 $thumbnail $imagePod->getImageBlob();
  44.                 header("Content-Type: image/png");
  45.                 echo $thumbnail;
  46.                 return;
  47.             }
  48.             if (!$name) {
  49.                 $image->writeImage($_SERVER['DOCUMENT_ROOT'] . '/cache' $img);
  50.                 touch($_SERVER['DOCUMENT_ROOT'] . '/cache' $img);
  51.             } else {
  52.                 $image->writeImage($_SERVER['DOCUMENT_ROOT'] . '/cache' $name);
  53.                 touch($_SERVER['DOCUMENT_ROOT'] . '/cache' $name);
  54.             }
  55.             header("Content-Type: image/jpeg");
  56.             echo $thumbnail;
  57.         } catch (\Exception $e) {
  58.             throw new NotFoundHttpException('Изображение не найдено',$e);
  59.         }
  60.     }
  61.     public static function watermark($img)
  62.     {
  63.         try {
  64.             if (class_exists('Imagick')) {
  65.                 $image = new Imagick($_SERVER['DOCUMENT_ROOT'] . $img);
  66.                 $wm = new Imagick($_SERVER['DOCUMENT_ROOT'] . '/troika.png');
  67.                 $widthRatio $image->getImageWidth() / 1096;
  68.                 $height $wm->getImageHeight() * $widthRatio;
  69.                 //$wm->adaptiveResizeImage($image->getImageWidth(), $height, false);
  70.                 $wm->scaleImage($image->getImageWidth(), $heightfalse);
  71.                 
  72.                 $image->setImageVirtualPixelMethod(\Imagick::VIRTUALPIXELMETHOD_TRANSPARENT);
  73.                 $image->compositeImage(
  74.                   $wm,
  75.                   \Imagick::COMPOSITE_PLUS,
  76.                   ($image->getImageWidth() - $wm->getImageWidth()) / 2,
  77.                   ($image->getImageHeight() - $wm->getImageHeight()) / 2
  78.                 );
  79.                 $image->writeImage($_SERVER['DOCUMENT_ROOT'] . $img);
  80.             }
  81.         } catch (\Exception $e) {
  82.             return;
  83.         }
  84.     }
  85. }
dobrowin | betleao | moverbet | winzada 777 | supremo | casadeapostas | dobrowin | betleao | moverbet | wazamba | fezbet | betsson | lvbet | dobrowin | betsul | pixbet | bwin | betobet | dobrowin | bet7 | betcris | blaze | 888 | betano | stake | stake | esportesdasorte | betmotion | rivalry | novibet | pinnacle | cbet | dobrowin | betleao | moverbet | gogowin | jogos win | campobet | mesk bet | infinity bet | betfury | doce | bet7k | jogowin | lobo888 | iribet | leao | dobrowin | allwin | aajogo | pgwin | greenbets | brapub | moverbet | onebra | flames | brdice | brwin | poplottery | queens | winbrl | omgbet | winbra | goinbet | codbet | betleao | fuwin | allwin568 | wingdus | juntosbet | today | talon777 | brlwin | fazobetai | pinup bet | bet sport | bet esporte | mrbet | premier bet | apostebet | spicy bet | prosport bet | bet nacional | luck | jogodeouro | heads bet | marjack bet | apostaganha | gbg bet | esoccer bet | esport bet | realbet | aposte e ganhe | aviator aposta | bet vitoria | imperador bet | realsbet | bet favorita | esportenet | flames bet | pague bet | betsury | doce888 | obabet | winzada | globalbet | bet77 | lottoland | 7gamesbet | dicasbet | esportivabet | tvbet | sportbet | misterjackbet | esportebet | nacionalbet | simplesbet | betestrela | batbet | Pk55 | Bet61 | Upsports Bet | roleta online | roleta | poker online | poker | blackjack online | bingo | 12bet | 33win | bet168 | bk8 | bong88 | bong99 | fcb8 | hb88 | hotlive | ibet888 | k8 | kubet77 | kubet | lode88 | mig8 | nbet | onebox63 | oxbet | s666 | sbobet | suncity | vwin | w88 | win2888 | zbet | xoso66 | zowin | sun | top88 | vnloto | 11bet | bet69 | 8xbet | Ceará | Paysandu | Juventude | Bahia | Sport | Cuiabá | Coritiba | Criciúma | Vitória | Fortaleza | Corinthians | São Paulo | Vasco | Grêmio | Fluminense | Cruzeiro | Botafogo | Flamengo | bingo slots | slots slots | hacker do slot | pg slot demo | slot win | pg slot soft | arne slot | riqueza slots | slots 777 | pg slot | 777 slot game | slot pg soft | hacker slot | 777 slots | slot-pg-soft | fortune ox demo grátis | demo fortune ox | fortune mouse demo | fortune ox demo | jogo fortune tiger | fortune tiger grátis | fortune tiger baixar | fortune tiger demo grátis | fortune tiger demo | fortune tiger 777 | 580bet | bet 7k | leao | luck 2 | john bet | 7755 bet | cbet | bet7 | pk55 | 8800 bet | doce | bet 4 | f12bet | bet7 | ggbet | bet77 | mrbet | bet61 | tvbet | pgwin | today | fuwin | brwin | bet7k | tv bet | allwin | stake | bwin 789 | lvbet | blaze | dj bet | umbet | b1bet | 20bet | bk bet | h2bet | 7kbet | fbbet | 9d bet | 9k bet | 73 bet | ktobet | 74 bet | betpix | betvip | batbet | onabet | f12bet | codbet | winbra | b2xbet | obabet | brlwin | onebra | winbrl | omgbet | queens | brdice | brapub | flames | betano | aajogo | iribet | pixbet | betsul | fezbet | curso beta | betway | bkbet | peixe beta | bet365 | pixbet | 4 play bet | 365bet | brxbet | 939 bet | seubet | cnc bet | gbg bet | 522bet | brl bet | pagbet | jonbet | jqk bet | 166bet | abc bet | bggbet | obabet | 136bet | mmabet | win bet | ir6 bet | 667bet | qqq bet | 193 bet | 3ss bet | 317 bet | kkk bet | 585 bet | 569 bet | vai bet | aaa bet | 969 bet | z11 bet | kw bet | 26 bet | mj bet | betio | 01 bet | ut bet | 9y bet | bet70 | f9 bet | hw bet | kg bet | 5e bet | bet br | hr bet | br bet | 75 bet | 03 bet | 6z bet | 6r bet | v6 bet | 78 bet | bt bet | 80 bet | 8g bet | 72 bet | xp bet | f12 bet | p9 bet | 5 bet | 4 bet | bet 4 | r7 bet | um bet | 29 bet | 5s bet | ck bet | pg bet | ea bet | 23 bet | bl bet | 3l bet | 2a bet | p7 bet | 888 bet | 707 bet | 361 bet | bet29 | 700 bet | 161 bet | bet777 | up bet | 58 bet | nn bet | 67 bet | 22 bet | 9g bet | 1x bet | bet10 | 70 bet | 2h bet | 9r bet | 16 bet | 81 bet | 7 bet | 5u bet | 6k bet | mg bet | b1 bet | 5h bet | je- bet | joya | hopa | nomini | ls bet | 1xbit | platin | ice bet | rant | bet us | bet go | 31 bet | slingo | flush | ice36 | weiss | bet9 | rabona | i bet | starda | dreams | bongo | snatch | 10 bet | daddy | metal | zep bet | drip | gama | drake | verde | shazam | wish | thor | exclusive | sol | highway | 500 casino | jazz | howl | supernova | sherbet | fresh | daddy | jet | wish | eclipse | inplay | drip | marvel | stake | scorpion | luxebet | drake | thor | puma | winzir | loki | shazam | rivalry | f1 casino | xgbet | sushi | bk8 | art casino | manga | pgasia | gemini | bingoplus | slot vip | help slot win | 8k8 slot | tadhana slot | jili slot | 55bmw slot | vip slot | nn777 slot | jili slot 777 | tg777 slot | w500 slot | phfun slot | bmw55 slot | sg777 slot | wj slot | slot free 100 | lucky cola slot | cc6 slot | taya777 slot | ph444 slot | slot games | fb777 slot | okebet slot | help slot | tg77 slot | phwin slot | vvjl slot | fc777 slot | slot vin | yy777 slot | define slot | define slot | inplay | 99bet | 60win | melbet | jollibet | jili slot | rich711 | tayabet | phl63 | unobet | 63jili | mwplay888 | gold99 | jolibet | ubet95 | nice88 | jili777 | nn777 | phlove | jiliko | 55bmw | phoenix game | 8k8 | cgebet | 7up gaming | diamond game | hellowin | win88 | big win | kabibe game | sabong bet | phcity | colorplay | tongits go | slotsgo | spinph | go perya | casino frenzy | aurora game | escala gaming | winning plus | bingo plus | ph dream | 747 live | niceph | lucky cola | pera play