Advertisement
kotvalera83

api.php

Oct 7th, 2015
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.03 KB | None | 0 0
  1. if ($images) {
  2.             foreach ($images as $value) {
  3.                 $f = $_SERVER['DOCUMENT_ROOT'] . '/uploads/images/full/'.$value->img;
  4.                 $org_info = getimagesize($f);
  5.                 $layer = new Image\Canvas($f);
  6.  
  7.                 $scale = $value->scale * 5;
  8.                 $scale_val = array(($org_info[0] * $scale), ($org_info[1] * $scale));
  9.                 $layer->fx('resize', $scale_val[0], $scale_val[1]); // Scale  
  10.                 $scale_min_x = ($scale_val[0] - $org_info[0]) / 2;
  11.                 $scale_min_y = ($scale_val[1] - $org_info[1]) / 2;
  12.                 $n_x = str_replace('px', '',$value->x) * $per - $scale_min_x; //- $scale * $per;
  13.                 $n_y = str_replace('px', '',$value->y) * $per - $scale_min_y; //- $scale * $per;
  14.  
  15.                 if ($value->borderRadius) {
  16.                     $rad = $value->borderRadius * $per;
  17.                     $layer->fx('corners', $rad, $rad); // Border-Radius
  18.                 }
  19.                 if ($value->borderD && $value->borderDC) {
  20.                     $s = ($value->borderD * $per) * $scale;
  21.                     $b = $value->borderD * ($per * 10);
  22.                     $layer->draw('border', $b , str_replace('#', '', $value->borderDC)); // Border-Color
  23.                     //$s = $b; //$b * $per * -1 / 2 + $b + 5; // $per;
  24.                 } else {
  25.                     $s = $b = 0;
  26.                 }
  27.  
  28.                 if ($value->borderRadius) {
  29.                     $layer->fx('corners', $rad, $rad); // Border-Radius
  30.                 }
  31.  
  32.                 if ($value->rotation) {
  33.                         $layer->fx('rotate', (360 - round((float)$value->rotation * 360)) ); // Rotation
  34.                         $img_temp = $_SERVER['DOCUMENT_ROOT'] . '/uploads/images/full/temp-' .$value->img;
  35.                         $layer->imageJpeg($img_temp);
  36.                         $lb = getimagesize($img_temp);
  37.                         $newSize = array(
  38.                                 "width" => $lb[0],
  39.                                 "height" => $lb[1]
  40.                          );
  41.                     $x = $n_x - ( $newSize["width"] - $scale_val[0]) / 2 + $s;
  42.                     $y = $n_y - ( $newSize["height"] - $scale_val[1]) / 2 + $s;
  43.                 } else {
  44.                         $x = $n_x - $s;
  45.                         $y = $n_y - $s;
  46.                 }                              
  47.                  
  48.                 $image = new Image\Canvas($name);
  49.                 $image->draw('layer', $layer, $x, $y, true);
  50.                 $image->imageJpeg($name);
  51.                 unset($image);
  52.                 unset($layer);
  53.             }
  54.        
  55.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement