Forum

Thread tagged as: Question, Error

Original image field Illegal string offset '_default'

Hello, for some reason just recently I'm getting an error on my blog post page. The second line is causing the error:

$customimg_1 = perch_blog_post_field(perch_get('s'), 'featureimage', true);
$customimg = $customimg_1['_default'];

The error I'm getting is:

Warning: Illegal string offset '_default' in /nfs/c11/h02/mnt/191364/domains/[website.com]/html/post.php on line 8

This was getting the original uploaded image as apposed to the resized version. Any ideas?

Brad Hardinge

Brad Hardinge 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You're asking for $customimg_1['_default'] but $customimg_1 doesn't have a key called _default.

Oh ok, strange, did something change as I'm sure this was working?

Is there a way to get the value of the original version of the image and not the resized version?

Drew McLellan

Drew McLellan 2638 points
Perch Support

What's the value of $customimg_1 ?

print_r($customimg_1);

It's just returning the cropped version of the image, Eg. "/perch/resources/imagename-w120h120.jpg"

So this line isn't returning an array like I believe it was before.

$customimg_1 = perch_blog_post_field(perch_get('s'), 'featureimage', true);

In my post.html template I have the following:

<perch:blog id="featureimage" type="image" width="120" height="120" crop="true" suppress="true" help="Should be a square with equal width and height. Minimum of 120 pixels." label="Feature Image" order="4" />
<perch:blog id="featureimage" type="image" width="80" height="80" crop="true" suppress="true" />

I use the 120x120 version and the 80x80 version in different templates, which work well. Is there any way I can get the original version of the image specially on the blog post page?

Drew McLellan

Drew McLellan 2638 points
Perch Support

So this line isn't returning an array like I believe it was before.

Before what change?

Is there any way I can get the original version of the image specially on the blog post page?

You probably don't want the actual original, as that could be any crazy size. If you add a new size to your template, I believe perch_blog_post_field() will return the first instance.

<perch:blog id="featureimage" type="image" width="1024" height="1024" suppress="true" help="Should be a square with equal width and height. Minimum of 120 pixels." label="Feature Image" order="4" />
<perch:blog id="featureimage" type="image" width="120" height="120" crop="true" suppress="true" />
<perch:blog id="featureimage" type="image" width="80" height="80" crop="true" suppress="true" />