Jump to content

Recommended Posts

Posted

Hello @ all,

I added a profil image to the user template in the backend.

Unfortunately I am not able to resize the image in frontend.

$img = $image->size($x, $y)

This function doesnt work for images which are stored in the user template.

Here is the complete code

$userimage = $user->userimage;    
if ($userimage){
       $options = array(
         'quality' => 90,
         'upscaling' => false, 
         'cropping' => 'north' 
       );  
       $img = $userimage->size(80, 100, $options);
       echo '<img src="'.$img.'"/>
}

I always got this error:

Error: Exception: Method Pageimages::size does not exist or is not callable in this context (in /home/.sites/24/site1275/web/wire/core/Wire.php line 350)

Imagefield setup:

Number of allowed images = 1

Format = auto

Is it not possible if I call an image from the user?

Thanks for your answeres

Posted

Seems like you're still getting an array of images, even though it should just return the single image with this field settings. Try using "$user->userimage->first()" or using Format = single for a temp. fix. Additionally I think you need to use "$img->url" in the echo line. The field not returning a Pageimage, but Pageimages seems to be a bug. It would be nice if you could report this on Github.

Could you do a var_dump($user->userimage); and check if it's a Image object?

"Method Pageimages::size" The error says enough.

  • Like 1
Posted

$userimage = $user->userimage->first() and $userimage = $user->userimage return both the same array with var_dump:

object(Pageimages)#656 (2) { ["count"]=> int(1) ["items"]=> array(1) { ["bewerbungklein-1.jpg"]=> string(20) "bewerbungklein-1.jpg" } } 

Strange behaviour because if the image is in a page template like $pageimage = $page->userimage this will work.

Posted

I have changed the image settings from "auto" to "single element (null if empty)" and now it works.

Thanks for your efforts

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...