Auto orient - FTP - ImageMagick

Hey all,

today I’ve a problem that I can’t seem to find a solution to.

I have a very basic Kirby webapp that displays images that have been uploaded by a smartphone to a folder by SFTP. The workflow is like this:

-Snap a picture
-open FTP app (Transmit on iOS)
-connect to server
-upload picture

nice and easy. my webapp creates thumbs from the images via imageMagic. I enabled autoOrient in the thumbs.php in the toolkit. It now turns the tumbnails correctly but the aspect ratio is totally off - the pictures look squashed.

Now I wonder is there a way to “preprocess” the pictures directly after upload so the thumbnails are generated out of an image that has bee already oriented correctly?
Hope I get the message across…

Thanks for any input!

Hm, generating thumbs shouldn’t mess with the aspect ratio of your images. Could you please post the code you are using?


<img class="lazy" src="loader.gif" data-original="<?php echo thumb($pic, array('width' => 400))->url() ;?>">					
							<a class="post-overlay swipebox" href="<?php echo $pic->url() ?>" title="Foto vom <?php $timestamp=$pic->exif()->times

I use swipebox to display the original sized picture. the picture is in the wrong orientation on swipebox too. that’s why I’d like to orient the pictures upon upload so everything is right in the first place. Or would that be the wrong approach?

oh and I use masonry in order to display the thumbnails…

I don’t have an answer for you but would like to point to this thread with a similar problem, where a plugin is used: Wrong orientation of images (Portrait/Landscape) after upload

Yeah I’ve seen that already but I don’t really get it. I think the image converter only works for images that have been uploaded via panel which I don’t do.

for the thumbs: can I call auto orient in my code or do I have to change it in thumbs php?

Since this is an option, you can call it in your code, just as you do with the other options.

Edit: If I get it right, you could try to use the ImageConverter plugin instead of the thumbs class. You don’t need to upload the images via the panel. But not tested, so I might be wrong.

If you want to use a panel hook, you would have to upload images via the panel, but that is not required for the plugin to work.

okay lets keep things tidy:

thumbs: I now call the autoorient option in my thumb array and yay it works! Images are still squashed though :frowning:
putting auto orient first and then resize (in my code) doesn’t change a thing. can I switch the order any other way?

picture preprocessing: I’ve no clue how to get the plugin to work :frowning: how does it recognize if new pictures have been uploaded? and how is it triggerd if pictures will not run through the panel?

Are the actual thumb files squashed? It could also be an issue with the frontend code.

Please see the README of the ImageConverter plugin. You can use this code wherever you want in your code.

nope. I tested it by disabling all frontend js stuff. The aspect ratio of the thumb image file itself is off. It’s the same issue @R4ttlesnake mentions in the thread @texnixe posted.

maybe I’m stupid but where do I put it? the images do not get processed in any way if i upload them to a directory via FTP, right? So where will the plugin get called?

You put the plugin code in your template, instead of the thumbs code. It doesn’t matter how the images are uploaded.

okay sorry for being stupid but i can’t seem to get the plugin with its params into my code so it does things right.

If I put it as a replacement for my thumb generating code as @texnixe proposed it just keeps duplicating the images inside the folder :worried:. Otherwise I get server error 500 when I play around too much hehe

do I still need the thumb class? like

thumb($pic, array('width' => 400))

I mean, yeah, that’s what it does: “This creates a new image in the same destination, as the original image and adds the suffix ‘_resized’ to the filename.”

You can use either of the two approaches. Using both is not very useful.

Thank’s all for your replies.

I solved the problem by modifing the thumb.php (kirby->toolkit->lib->thumb.php) like this:

$command[] = '-quality ' . $thumb->options['quality'];

if($thumb->options['blur']) {
$command[] = '-blur 0x' . $thumb->options['blurpx'];

if($thumb->options['autoOrient']) {
$command[] = '-auto-orient';

$command[] = '"' . $thumb->destination->root . '"';

exec(implode(' ', $command));


basically I put auto-orient at the very pottom so it’s the last operation the script does. This way it does not interfere with image resizing that now is performed first!

Thanks @Malvese!

1 Like