Exemple #1
0
function affect_rgba($d, $clr)
{
    $r = explode('#', $d);
    $n = count($r);
    $clr[0] = '';
    for ($i = 0; $i < $n; $i++) {
        if (substr($r[$i], 0, 1) == '_') {
            $klr = str_until($r[$i], ';,) ');
            $vlr = substr(trim($klr), 1);
            if (strpos($vlr, '.')) {
                list($abs, $alp) = explode('.', $vlr);
                $ret .= str_replace($klr, hexrgb($clr[$abs], $alp / 10), $r[$i]);
            } else {
                $ret .= '#' . str_replace($klr, $clr[$vlr], $r[$i]);
            }
        } elseif ($i) {
            $ret .= '#' . $r[$i];
        } else {
            $ret .= $r[$i];
        }
    }
    return $ret;
}
Exemple #2
0
 public function resizeImage($id, $size = null)
 {
     $asset = is_object($id) ? $id : $this->find($id);
     if ($asset == null) {
         return $this->missingImageResponse();
     }
     if ($asset->isImage() == false && $asset->isSVG() == false) {
         return 'Error: Wrong File Format';
     }
     $url = $asset->relativeURL();
     $params = $this->parseSizeFromString($size);
     // if we are svg just return the file
     // todo: parse svg and alter width/height
     if ($asset->isSVG()) {
         $svgFile = File::get($url);
         if ($params->s != null) {
             if ($params->retina) {
                 $params->s *= 2;
             }
             $svgFile = $this->resizeSVG($svgFile, $params->s, null);
         } else {
             if ($params->w != null || $params->h != null) {
                 if ($params->retina) {
                     if ($params->w != null) {
                         $params->w *= 2;
                     }
                     if ($params->h != null) {
                         $params->h *= 2;
                     }
                 }
                 $svgFile = $this->resizeSVG($svgFile, $params->w, $params->h);
             }
         }
         if ($params->raw) {
             $str = strpos($svgFile, "<svg") ? substr($svgFile, strpos($svgFile, "<svg")) : $svgFile;
             return Response::make($str, 200, array('Content-Type' => 'image/svg+xml'));
         }
         return Response::make($svgFile, 200, array('Content-Type' => 'image/svg+xml'));
     }
     $info = pathinfo($url);
     $basename = str_until($size, ".");
     $filename = $size ? $info['filename'] . '_' . $basename . '.' . $info['extension'] : $info['filename'] . '.' . $info['extension'];
     $path = $info['dirname'] . '/' . $filename;
     if (File::exists($path)) {
         $file = new \Symfony\Component\HttpFoundation\File\File($path);
         $mime = $file->getMimeType();
         return Response::make(File::get($path), 200, array('Content-Type' => $mime));
     }
     $img = Image::cache(function ($image) use($url, $params, $path) {
         $image->make($url);
         if ($params->s != null) {
             if ($params->retina) {
                 $params->s *= 2;
             }
             $image->fit($params->s, $params->s)->sharpen(3);
             /*
             				$image->resize($desw, $desh, function ($constraint) {
                 				$constraint->aspectRatio();
             				})->crop($s, $s);*/
         } else {
             if ($params->w != null || $params->h != null) {
                 if ($params->retina) {
                     if ($params->w != null) {
                         $params->w *= 2;
                     }
                     if ($params->h != null) {
                         $params->h *= 2;
                     }
                 }
                 $image->resize($params->w, $params->h, function ($constraint) {
                     $constraint->aspectRatio();
                 });
             }
         }
         $image->save($path);
         return $image;
     });
     $file = new \Symfony\Component\HttpFoundation\File\File($url);
     $mime = $file->getMimeType();
     return Response::make($img, 200, array('Content-Type' => $mime));
 }