Forum

Thread tagged as: Question, Blog

Image Resize in Master Template for another Template?

I'm wondering if I can have an image uploaded in a master template, then be able to have/resize multiple sizes of the same image to be used in a different template. I believe that I have read in the Docs that perch resizes images upon admin image upload. If that is the only time an image can be resized, can one use the perch tags to "make" the images, hide/suppress them, and access them later?

<perch:content type="image" id="image" label="Image" width="1600"  />
<perch:content type="image" id="image" label="Image" width="800" suppress="true" />
<perch:content type="image" id="image" label="Image" width="400" suppress="true" />

^ This in the master template and be able to access all sizes in a different template?

In my particular case, I'm working with the Blog App. So the master template would be post.html.

Nicholas Nelson

Nicholas Nelson 0 points

  • 7 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

That's right. If you want image sizes to use elsewhere set them up in the master template.

Cool. So when I would like to call on an image I would write something like this:

<perch:content type="image" id="image" width="800" />

and that should call the 800px wide image that had previously been created?

Rachel Andrew

Rachel Andrew 394 points
Perch Support

Yes - although if you are in a blog template you need to use perch:blog tags not perch:content.

https://docs.grabaperch.com/docs/blog/template-tags/

Ah yes. However it seems that after I added the tag and uploaded a new photo, the blog post doesn't save correctly. I hit SAVE and just get a white screen. I re-opened the blog back end, when to edit the post and no image is saved in the image field I'm working with.

I do have "development mode" on in the perch config file if that makes a difference?

Well I got the blog to save alright when the image resize is suppressed in the post.html template. However the image resize call doesn't seem to work.

I then tried to display a resized image in post.html. That is, just delete the suppress option. Now when I try to save a new blog, it again just gives me a white screen and does not save.

Rachel Andrew

Rachel Andrew 394 points
Perch Support

Please show us your complete template.

Okie Dokie, here is post.html

<perch:blog id="postTitle" type="text" label="Title" required="true" size="xl autowidth" suppress="true" />
<perch:blog id="featureImage" type="image" label="Feature Image" suppress="true" />
<perch:blog id="postTagline" type="textarea" label="Post Tagline" size="xs autowidth" required="true" suppress="true" />
<perch:blog id="featureImageColor" type="radio" label="Feature Image Text Color" options="black,white" suppress="true" />
<perch:blog id="postDescHTML" type="textarea" label="Post" editor="ace" size="xxl autowidth" required="true" suppress="true"
    divider-before="Content - image classes: full-image, big-image, med-image, sm-image" />
<perch:blog id="postDateTime" type="date" label="Date" time="true" divider-before="Meta information" suppress="true" />
<perch:blog id="visualSecCat" type="text" label="Visual Section & Categories" suppress="true" />

<!-- Resize feature image -->
<perch:blog id="featureImage" type="image" width="800" suppress="true" />

<!-- When trying to use a resized image in this template I deleted the above resize and used: -->
<img src="<perch:blog id="featureImage" type="image" width="800" />">


<h2 class="post-tag"><perch:blog id="postTagline" /></h2>

<perch:blog id="postDescHTML" html="true" />

<span class="post-date"><perch:blog id="postDateTime" format="%x" /></span>
Rachel Andrew

Rachel Andrew 394 points
Perch Support

Can I see your Diagnostics Report please, you can find that under Settings.

Have you also checked your PHP error log for any PHP errors, if you are getting a white screen you have a PHP error and it would be unlikely that a template issue would cause that so I am wondering if some other problem is occurring.

Diagnostics Report

Perch: 2.5.4, PHP: 5.5.3, MySQL: 5.5.33, with PDO
Server OS: Darwin, apache2handler
Installed apps: content (2.5.4), assets (2.5.4), perch_blog (4.1)
App runtimes: <?php $apps_list = array( 'content', 'perch_blog' );
PERCH_LOGINPATH: /perch
PERCH_PATH: /Users/nicholasnelson/Dev_Projects/nn_blog/nn_blog_perch/perch
PERCH_CORE: /Users/nicholasnelson/Dev_Projects/nn_blog/nn_blog_perch/perch/core
PERCH_RESFILEPATH: /Users/nicholasnelson/Dev_Projects/nn_blog/nn_blog_perch/perch/resources
Image manipulation: GD
PHP limits: Max upload 32M, Max POST 32M, Memory: 32M, Total max file upload: 32M
Resource folder writeable: Yes
HTTP_HOST: nn-blog.local
DOCUMENT_ROOT: /Users/nicholasnelson/Dev_Projects/nn_blog/nn_blog_perch
REQUEST_URI: /perch/core/settings/diagnostics/
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php

Would you happen to like the extended version?

Looking into my apache error log I don't see anything that really sticks out at me, but I don't really know how to read an error log.

[Sat Aug 09 17:15:25 2014] [notice] Digest: generating secret for digest authentication ...
[Sat Aug 09 17:15:25 2014] [notice] Digest: done
[Sat Aug 09 17:15:25 2014] [notice] Apache/2.2.25 (Unix) mod_ssl/2.2.25 OpenSSL/0.9.8y DAV/2 PHP/5.5.3 configured -- resuming normal operations

This pattern repeats but unless that is just starting mamp, I don't know what it means. Also looks like I have some errors regarding a missing favicon.png file. Would that disrupt Perch?

Rachel Andrew

Rachel Andrew 394 points
Perch Support

It's your PHP Error log you need to look at. If you cause this white screen and look in the log the relevant error will be at the time the error occurred.

Ah yes, sorry.

[10-Aug-2014 21:55:38 UTC] PHP Fatal error:  Allowed memory size of 33554432 bytes exhausted (tried to allocate 11520 bytes) in /Users/nicholasnelson/Dev_Projects/nn_blog/nn_blog_perch/perch/core/lib/PerchImage.class.php on line 463

Hmm I did try to resize an image to 400px which worked. When I tried a resize to 1600px it did not work. So it seems there is a size or memory issue? The original image is 2880px at 450KB. IS perch trying to create/save the resized image at a higher file size?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Handling large images takes quite a bit of memory - you're running out. There's not much Perch can do to prevent that, unfortunately.

Alright. I'll create another field for a smaller image. Thanks for your time!