👨💻 My name is Thomas Günther and I'm a web designer and developer.
👨🍳 I come from a family of bakers, hence I'm a Medienbäcker.
💆♂️ I almost exclusively use Kirby.
🌲 I live in the black forest.
Automatically resize images on upload
👨💻 My name is Thomas Günther and I'm a web designer and developer.
👨🍳 I come from a family of bakers, hence I'm a Medienbäcker.
💆♂️ I almost exclusively use Kirby.
🌲 I live in the black forest.
Although the image resizing features is very useful on most pages, there might be occasions you want to allow users to upload in higher resolution, for specific use-cases. What about having an ignore_page
(Array) or ignore_template
(Array) setting in the config file?
Hey @medienbaecker, first of all: I love this plugin, big up!
Is it possible to add the option to change the quality of the image? (Like the Kirby Resize option)
All the best, K
Hi,
thanks for Your plugin!
I have extended it a little bit, since I needed an option to also scale down images in portrait mode.
It's also possible to set up a "longest side", and the script will then take care of both orientations (maxWidth & maxHeight will be ignored, if given).
I'm sure, this can be optimized, but maybe someone finds it useful anyway.
Cheers,
Cris
// config.php
'medienbaecker.autoresize.sizes' => [
'maxWidth' => 1600, // landscapes
'maxHeight' => 1200, // portraits
//'longestSide' => 1200, // portrait and landscape
],
// index.php
Kirby::plugin('medienbaecker/autoresize', [
'options' => [
'sizes' => [
'maxWidth' => 1600,
'maxHeight' => 1600,
'longestSide' => null,
]
],
'hooks' => [
'file.create:after' => function ($file) {
$option = option('medienbaecker.autoresize.sizes');
$mW = $option['maxWidth'];
$mH = $option['maxHeight'];
$ls = $option['longestSide'];
$oldW = $file->width();
$oldH = $file->height();
if(!empty($ls)){
$maxW = $ls;
$maxH = $ls;
} else {
$maxW = $mW;
$maxH = $mH;
};
if($file->isResizable()) {
if($oldW > $maxW || $oldH > $maxH){
try {
kirby()->thumb($file->root(), $file->root(), [
'width' => $maxW,
'height' => $maxH,
]);
} catch (Exception $e) {
throw new Exception($e->getMessage());
}
}
}
},
'file.replace:after' => function ($newFile, $oldFile) {
kirby()->trigger('file.create:after', $newFile);
}
]
]);
It would be very nice if the plugin would be installable by composer.
composer require medienbaecker/kirby-autoresize
fails right now:
Could not find a matching version of package medienbaecker/kirby-autoresize. Check the package spelling, your version constraint and that the package is available in a stability which matches your minimum-stability (stable)
https://getkirby.com/docs/guide/plugins/plugin-setup-basic#the-composer-json
Thanks in advance :)
This isn't a problem for me, but I noticed this behavior. When I remove ...excludePages in the config, it works on the ...excludeTemplates.
If this is expected, should I add it to the readme?
While actual version is 2.1.3, which leads to all sorts of funny errors. Could you please release it on packagist as well?
This plugin has always worked, but now seems to throw an exception with Kirby 3.6. The error message is: Cannot redeclare autoresize() (previously declared in \site\plugins\autoresize\index.php:3)
The autocrop works fine for new images, but when I try to replace an existing image I get
Argument 2 passed to Kirby\Cms\App::trigger() must be of the type array, object given,
called in /rootpath/plugins/autoresize/index.php on line
Any ideas how to fix?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.