getkirby-v2 / toolkit

This is the deprecated toolkit for Kirby v2.
http://getkirby.com
81 stars 50 forks source link

Thumbs for files outside the content folder since 2.3.0 #166

Closed MathiasGmeiner closed 8 years ago

MathiasGmeiner commented 8 years ago

Before 2.3.0 it was possible to generate the thumbs as described in https://getkirby.com/docs/templates/thumbnails#thumbs-for-files-outside-the-content-folder

but after the update to 2.3.0 two things happen:

This is the code I used before 2.3.0:

$media = new Media(
  // the absolute path for the file
  kirby()->roots()->index() .'/images/'. $image,         
  // the absolute url
  kirby()->urls()->index() .'/images/'. $image
);

$image = thumb($media, array('width' => 936, 'height' => 702, 'crop' => true, 'quality' => 40))->url();

and after some debugging this is the working code for 2.3.0:

$media = new Media(
  // the absolute path for the file
  kirby()->roots()->index() .'/images/'. $image,         
  // the absolute url
  kirby()->urls()->index() .'/images/'. $image
);

$image = thumb($media, array('width' => 936, 'height' => 702, 'crop' => true, 'quality' => 40, 'driver' => 'gd', 'root' => $_SERVER['DOCUMENT_ROOT'] .'/thumbs/'));
lukasbestle commented 8 years ago

As far as I can tell, this is the intended behavior since 2.3.0. It makes the Toolkit more independent from the CMS so that it works for users who don't also use the CMS.

Have you tried using the new Asset class?

$asset = new Asset('images/' . $image);
$image = $asset->thumb(array('width' => 936, 'height' => 702, 'crop' => true, 'quality' => 40))->url();

If that works without any further changes (as it should), we will instead update the documentation.

MathiasGmeiner commented 8 years ago

I will try new Asset next week, thanks!

MathiasGmeiner commented 8 years ago

Works great, thanks!