I'm implementing the Intervention package to dynamically resize images in my site. It's working quite well and I'm happy with it. Here's an example of how I do it:
Route::get('images/ads/{width}-{ad_image}-{permalink}.{format}', function($width, $image, $permalink, $format)
{
$img = Image::make($image->path)
->resize($width, null, function($constraint){
$constraint->aspectRatio();
});
return $img->response($format);
});
Recently, I thought of making my site load faster by auto-compressing my views via a middleware:
class HTMLminify
{
public function handle($request, Closure $next) {
$response = $next($request);
$content = $response->getContent();
$search = array(
'/\>[^\S ]+/s', // strip whitespaces after tags, except space
'/[^\S ]+\</s', // strip whitespaces before tags, except space
'/(\s)+/s' // shorten multiple whitespace sequences
);
$replace = array(
'>',
'<',
'\\1'
);
$buffer = preg_replace($search, $replace, $content);
return $response->setContent($buffer);
}
}
Then came the nightmare. Browsers report that the images processed by Intervention are now "truncated" and won't display. Turning off the middleware displays the images without a problem.
As far as I can see from the HTMLminify class' codes is that it modifies the output generated from the views and removes the whitespaces and don't see any reason how it could interfere with images.
Any ideas, guys?
Thanks in advanced.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire