Search code examples
modx

MODx phpthumbof doesn't work in template


I use phpthumbof in different parts of my website to resize images

It works perfectly in chunk using pdoresources from template

[[pdoResources?
  &parents=`2`
  &limit=`1`
  &depth=`2`
  &hideContainers=`1`
  &includeTVs=`post-main-image`
  &tpl=`main-post`
]]

here is code of chunk:

<img src="[[+tv.post-main-image:phpthumbof=`w=360&h=223&zc=1`]]">

but it doesn't work when I call it directly from template

[[*post-main-image:phpthumbof=`w=360&h=223&zc=1`]]

It shows image but doesn't affect on it's size or crop. How can I solve it?


Solution

  • Some things to try:

    Is the output of the tv post-main-image set to text? (I'm assuming yes.)

    In your template example, what happens when you add an ampersand & before w=360?

    [[*post-main-image:phpthumbof=`&w=360&h=223&zc=1`]]

    You can use phpThumbOf as a snippet instead of an output modifier:

    [[!phpthumbof? &input=`[[+post-main-image]]` &options=`&w=360&h=223&zc=1`]]

    (untested)

    You can use pThumb instead (I have much better luck with it). https://github.com/rthrash/pThumb