$args['url'], 'height' => $args['h'] ?? NULL, 'width' => $args['w'] ?? NULL, 'canvasheight' => $args['ch'] ?? NULL, 'canvaswidth' => $args['cw'] ?? NULL, 'format' => $args['format'] ?? NULL, 'fill' => $args['fill'] ?? NULL, ]; $cachefolder = []; foreach($options as $key => $option) { if($key != 'url' && $option != NULL) $cachefolder[] = $key . '-' . $option; } $cachefolder = implode('_', $cachefolder); $cachefile = preg_replace("/[^A-Za-z0-9]/", '-', $options['url']); if(is_dir('cache/' . $cachefolder)) { if(is_file('cache/'. $cachefolder . '/' . $cachefile) && (filemtime('cache/'. $cachefolder . '/' . $cachefile) > (time() - (60*60*24*30)))) { sendFile('cache/' . $cachefolder . '/' . $cachefile); exit; } }; $imagecontent = file_get_contents($options['url']); if(isSvg($imagecontent)) { $image = new Imagick(); $image->setBackgroundColor('none'); $image->readImageBlob($imagecontent); $image->setImageFormat("png64"); $image->resizeImage(2000,2000, imagick::FILTER_QUADRATIC, 0.7, true); $imagecontent = $image->getImageBlob(); } $transparent = (new \Intervention\Image\Colors\Rgb\Color(0,0,0,0)); // to finally create image instances $image = $manager ->read($imagecontent) ->pad($options['width'], $options['height'], $transparent) ->resizeCanvas($options['canvaswidth'], $options['canvasheight'], $transparent); if (isset($options['fill'])) { $image = $image->blendTransparency($options['fill']); } // send HTTP header and output image data if(!is_dir('cache/' . $cachefolder)) mkdir('cache/' . $cachefolder); if(isset($args['format'])) { $image = $image->encodeByExtension($args['format']); } $image->save('cache/' . $cachefolder . '/' . $cachefile); sendFile('cache/' . $cachefolder . '/' . $cachefile); function sendFile($filepath) { $filecontents = file_get_contents($filepath); $mime = finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $filecontents); $length = strlen($filecontents); $response = new Response($filecontents, Response::HTTP_OK, ['Content-Type' => $mime, 'Content-Length' => $length]); $response->send(); } function isSvg($content) { // Controleer of de inhoud begint met de kenmerkende SVG-declaratie return strpos($content, '