13

I'm trying to get Craft to render an image transform defined in the control panel. No image is added to the "filelocation/_transformhandle" folder and returns the url "/cpresources/transforms/98" where 98 is the transform index.

I have tried clearing the cache and db table already as well as updating the asset index. I have double checked the sources paths and it is not a file permission issue.

Code example as a matrix block:

{% elseif block.type == "slideShow" %} 
{% if block.galleryImages|length>0 %}

{% for image in block.galleryImages %}
    {{ image.aboutText }}
    <img src="{{ image.getUrl('galleryHorizontal') }}">
{% endfor %}
{% endif %}

I tried using the other methods on this page in the docs with the same result. http://buildwithcraft.com/docs/templating/assetfilemodel

Thanks!

19

That’s what getUrl() returns if the transform hasn’t been generated yet. When the browser requests that URL, Craft will generate the transform, and respond with a 302 redirect to the actual image URL.

Update: As of Craft 2.2, even if the transform generation URL doesn’t get directly requested (e.g. if it’s a social media image, or a srcset size that doesn’t apply to the browser), it will still get generated automatically as a background task as soon as Craft is done serving the page.

The next time getUrl() gets called (after the transform has been generated), the image URL will be returned directly.

If you would prefer that getUrl() actually generates the transform itself and immediately returns the image URL (perhaps because the output is getting cached by Varnish or something), you can open up craft/config/general.php and add this to your config array:

'generateTransformsBeforePageLoad' => true,

(See http://buildwithcraft.com/docs/config-settings#generateTransformsBeforePageLoad for details.)

  • I'm not caching the output. When the code is loaded by the browser the transformed jpg isn't loaded. The console says: Failed to load resource: the server responded with a status of 404 (Not Found). – FrankFlitton Jul 8 '14 at 17:10
  • 3
    Thanks for the hot tip with the 302 redirect! It was a sources issue. I changed it to File System Path: ./assets/images/Gallery/ and URL: /assets/images/Gallery/ in the CP and it works fine now. – FrankFlitton Jul 8 '14 at 17:50
  • Glad you got it sorted :) – Brandon Kelly Jul 8 '14 at 19:22
3

I've also seen this triggered by directory/file permission issues, namely that Craft didn't have write access to the image asset directory. Once I fixed the permissions with chmod, my specific problem was solved.

chmod 777 -R images
1

I also had this problem and changing the setting worked for me.

I did have a problem where the transforms then showed a 404 page rather than the actual image. Clearing the 'Cache' via settings in Craft CMS fixed this.

1

I have had the same issue when using a custom function to calculate the image's resulting size.

The problem happened when that function returned decimals. So if you ever calculate the transform's dimensions, make sure you round the results to avoid this.

1

for me trying the happylager template I had to change access to to site dir

chmod a+w public/assets/site

  • This indicates a server configuration issue - you should never need to give 'all' write access. Definitely do not do this in production! – Jeremy Daalder Aug 9 '17 at 3:40
  • you are right, I had wrong user and group settings. – toy Aug 10 '17 at 9:06
0

Still unanswered, and still a longstanding issue for me, is why it is looking in /cpresources/, which I thought meant Control Panel resources, for a photo that is not a Control Panel resource.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.