Skip to content

Instantly share code, notes, and snippets.

@bastianallgeier
Created November 16, 2015 15:39
Show Gist options
  • Save bastianallgeier/23edbb66253186fa63c8 to your computer and use it in GitHub Desktop.
Save bastianallgeier/23edbb66253186fa63c8 to your computer and use it in GitHub Desktop.
<?php
// resize an image by the width
$image->resize($width)->url();
// resize by width and height. The bigger one will be downscaled
$image->resize($width, $height)->url();
// adjust the jpeg compression
$image->resize($width, $height, $quality)->url();
// pass null as second argument if you only want to specify the width but also change the quality
$image->resize($width, null, $quality)->url();
// crop an image: by defining only the width the crop will be square
$image->crop($width)->url();
// speificy a width and height to get non-square crops
$image->crop($width, $height)->url();
// adjust the jpeg compression
$image->crop($width, $height, $quality)->url();
// pass null again for the height if you want a square crop but also adjust the quality
$image->crop($width, null, $quality)->url();
@bastianallgeier
Copy link
Author

Both methods return a Kirby media object which has tons of additional methods. So you can also do stuff like this:

echo $image->resize(300)->height();

echo $image->resize(300)->niceSize();

echo $image->resize(300)->ratio();

echo $image->resize(300)->orientation();

// etc. 

You can find more about it here: http://getkirby.com/docs/toolkit/api#media

@mattlenz
Copy link

@bastianallgeier is there still an equivalent of 'grayscale' => true with this new syntax?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment