Jump to content

Userimage and resize doesnt work on frontend with API


Juergen
 Share

Recommended Posts

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

$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.

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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