Resizing larger side

I seem to not understand something about thumb and resize.

This code seems (seems) to work [edit, actually it seems to work on recognizing if width or height is larger, but I think not on the resize]

<?php if( thumb($p->image())->width() > thumb($p->image())->height() ): ?>
  <?php $lImage = $p->image()->resize(627) ?>
<?php endif ?>

But I was trying to write a function to resize only larger side and I keep getting errors, this is the code:

<?php
	function resizelarger($img, $newSize){ 
		if( thumb($img)->width() > thumb($img)->height() ){
			if( thumb($img)->width() >= $newSize ){
				return $img->resize($newSize)->url();
			}
		} else {
			if(thumb($img)->height() >= $newSize){
				return $img->resize(null, $newSize);
			}
		}
	}

I call it like this:

<img src="<?= resizelarger($p->image(), "2000")->url() ?>">

But I get “Call to a member function url() on null”

What am I doing wrong, please?

Thank you

I also tried with this code:

<?php
	function resizelarger($img, $newSize){ 
		if( $img->width() > $img->height() ){
			if( $img->width() >= $newSize ){
				return $img->width($newSize)->url();
			}
		} elseif( $img->height() >= $newSize ){
			if( $img->height() >= $newSize ){
				return $img->height($newSize);
			}
		} else {
			return $img->url();
		}
	}

Calling it like this, as it seemed to me that perhaps these methods return the url directly:

<img class="" src="<?= resizelarger($p->image(), 2000) ?>">

But I still seem to be getting the unresized original image url.

Thanks

It’s late and my brain is tired, but i think your getting the error becuase your not actually telling it which image to use… this seams wrong…

<img src="<?= resizelarger($p->img(), "2000")->url() ?>">

what is $p->img()?

oops, that is actually a tipo, I of course am using $p->image(), corrected.

I have the impression that no thumbnail is being created at all in the thumbs folder. That folder has the same owner, group and permissions than my content folder tho.

You function should. look like this:

function resizelarger($img, $newSize){
		if( $img->width() > $img->height() ){
			if( $img->width() >= $newSize ){
				return $img->width($newSize)->url();
			}
		} elseif( $img->height() >= $newSize ){
			if( $img->height() >= $newSize ){
				return $img->height($newSize)->url();
			}
		} else {
			return $img->url();
		}
	}

Right, I was missing an url(), thank you.

But still with that I get the original image. And no image seems to be created in the thumbs folder. Although there are folders for the pages whose images I am trying to resize.

All those folders are drwxrwxr-x and owner and group are www-data (linux apache)

I am on localhost.

What happens if you resize the image the standard kirby way? just to rule out ur function and the folder access rights.

Which is the “standard kirby way”

And thanks for taking the time and effort to help!

<?= thumb($page->image('yourimage.jpg'), array('width' => 300)); ?>

From this page in the documentation.

Before I try that, I need to say that on my remote repo the images are correctly resized and served from the thumbs folder. So the function seems to work.

Then there must be some kind of problem with either whatever engine kirby is using for resizing on my local host or permissions?

hmm

Usual culprits on local host are basic php.ini settings, which are not usually sufficiant. Are you giving local host php enough ram to work with?

Look in php.ini and find the below setting…

memory_limit = 64M

Set it to at least 64, but personally i give it 128M, because i often work with image heavy sites, with large images.

upload_max_filesize = 10M
post_max_size = 10M

memory_limit = 128M

Interesting… try my last answer then.

Are you using gd or imagemagick?

That is what I was looking for now, in a php info file I don’t find GD or imagemagick listed, except for GD Imaging under modules for php credits. But no “GD” section, nor imagemagick.

Hmm

What kind of local server are u using? Mamp? Wamp? Built in…?

I am on linux, and I just installed and configured all the things by cli long ago, Apache2, php7, mysql, probably following guides.

I am still learning.

Hm, then maybe none of the image libraries are installed… What do you get if you

dump(gd_info());

I assume you haven’t set the thumb library to im in config, have you?

Error

Call to undefined function gd_info()

And no, I haven’t changed the thumb library, this means I don’t have gd or it is not configured to work with php right?

Yes I can confirm, I installed Php7.0-gd and it is working well now.

I guess it was obvious.

Thank you for your help.