Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Position syntax using FPF with Imager and Eager Loaded Images #10

Open
jayhlee opened this issue Mar 22, 2017 · 15 comments
Open

Position syntax using FPF with Imager and Eager Loaded Images #10

jayhlee opened this issue Mar 22, 2017 · 15 comments

Comments

@jayhlee
Copy link

jayhlee commented Mar 22, 2017

I'm having trouble getting the correct syntax for my FPF field when I'm using it with Imager with eager-loaded images. Specifically, I'm not sure what follows "position: " because this doesn't seem to work:

{% set image = entry.projectFeatureImage[0] ?? null %}
{% set transformedImages = craft.imager.transformImage(image, [
	{ width: 1200 },
	{ width: 720 },
	{ width: 290 }
	], {
		format: 'jpg',
		ratio: 3/4,
		allowUpscale: false,
		mode: 'crop',
		position: image.focalPointField,
		interlace: true
	}) %}

When I test out {{ image.focalPointField }}, it outputs the correct percentages that I set for my image positions (e.g. '30% 40%'). However, it doesn't seem to work within the Imager code syntax. Any guidance would be great!

@aelvan
Copy link
Owner

aelvan commented Mar 25, 2017

That looks correct to me. What's the error you're seeing?

@jayhlee
Copy link
Author

jayhlee commented Mar 25, 2017

I get an "Undefined offset: 1" PHP notice. Specifically, it says the error is at:

craft/plugins/imager/services/ImagerService.php(914), which is...
list($leftOffset, $topOffset) = explode(' ', $position);

@aelvan
Copy link
Owner

aelvan commented Mar 26, 2017

Weird. Since you're mentioning eager loading, does it work if you don't eager-load?

@jayhlee
Copy link
Author

jayhlee commented Mar 27, 2017

Just tried using it without the eager loading, but I still get the same error thrown. Here's what it's showing.

screen shot 2017-03-27 at 2 50 40 pm

@aelvan
Copy link
Owner

aelvan commented Mar 28, 2017

There must be something wrong with the value that is being passed in, that space in '30% 40%' maybe isn't a space? Is '30% 40%' the default value you've assigned to the field? Try erasing the value, write it again, save, and check again.

Also, what happens if you replace the position part with position: image.focalPointField ?? '50% 50%',?

@lukakemperle
Copy link

+1

@jayhlee
Copy link
Author

jayhlee commented Mar 29, 2017

@aelvan I tried removing the positions, but I get the same error. I also replaced the position to what you wanted me to try out, but I get the same error.

@aelvan
Copy link
Owner

aelvan commented Mar 29, 2017

Can you try opening up craft/plugins/imager/services/ImagerService.php, right before line 914 add Craft::dd($position), and let me know what the output is.

Is there only this one image on the page, or several? If there're more than one, can you try to make a minimal test case with only one and see if you still get the error.

@jayhlee
Copy link
Author

jayhlee commented Apr 3, 2017

@aelvan Hi Andre, Sorry about the late reply. I reduced the images down to one on the page and added the line of code as you instructed. Here's the error message:
errors

@ghost
Copy link

ghost commented Jun 21, 2017

Any progress on this? I'm getting the same error.

@aelvan
Copy link
Owner

aelvan commented Jun 22, 2017

Yeah, this keeps popping up from time to time, and the reason is always that an invalid value is being passed. I'd check (and double check) that the default values that is set in the config and on the field(s), are correct. It's suppose to be xx% xx%, with a plain space inbetween. No dash, comma, invisible utf-8 space thingy, or whatever...

@ghost
Copy link

ghost commented Jun 22, 2017

Ah, I see what the issue is. You HAVE to input a default value for the FocalPoint field. For some reason the default value FocalPoint says it will output doesn't get outputted if you leave it blank. So looping over an image array with some images having a focal point and some not was causing the error. As soon as I added a default value (50% 50%) to my field everything worked fine.

@aelvan
Copy link
Owner

aelvan commented Jun 22, 2017

Ok, that sounds like a bug. I'll have a look at it.

@samlous
Copy link

samlous commented Sep 4, 2017

I got the same problem. While waiting for a fix, is there a simple code solution I can use, instead of looping through all images and giving them a default value?

@ghost
Copy link

ghost commented Sep 4, 2017

@samlous All you have to do is put the default value in the Focal Point Field when you create it, not every time you insert images in the code. Once that default value is there you should be fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants