Displaying images... how to
#1
Posted 12 December 2011 - 01:46 AM
I'm starting to put together my first processwire site, it will be a portfolio style site for a friend of mine.
I'm following the head.inc > page-template.php > footer.inc structure.
I'm going to have a portfolio-page.php for each project. Sometimes there will be multiple images per project, and i want a piece of text attached to each image to display. I'm happy for the page to just scroll down when theres multiple images. The images will be on the large side.
What is the best approach?
– Is it best to create 'sub pages' under each project for each additional image? So there would be a template for individual images?
– Or is there a way to add extra images with text straight to the main portfolio-page.php template?
I have used the 'images' field but it doesn't display the description. I would prefer to wrap each image and text in a div.
I'm not sure where to start in the API for this information?, I guess i am looking for examples of the code so I can understand it better.
thanks,
Alex
#2
Posted 12 December 2011 - 02:26 AM
<?php
//Display images if available
if(count($page->images)) {
echo '<div id="gallery">';
$n = 0;
foreach($page->images as $image) {
$resized_image = $image->size(236,225);
echo "<p><img class='photo' src='{$resized_image->url}' alt='{$image->description}' width='236' height='225' />";
echo "<br />{$image->description}</p>";
$n++;
}
echo "</div>";
}
More examples are available here: http://processwire.c...k-start/images/
This is also a useful forum topic: http://processwire.c...topic,97.0.html
#3
Posted 12 December 2011 - 04:22 AM
I've done a couple of artist portfolio sites (example: http://illo.clientsite.net.au) and almost never use the image description field. I usually put each artwork on its own page. You don't really need a template file for each image so long as you have the fields you want set up.
There's a few ways to display images as I've discovered with PW. It all depends on the design.
Cheers
Marty
#4
Posted 12 December 2011 - 06:23 AM
Thanks for the replies.
I tried Formmailer's code, got it to display description but not images, Have tried some code from the quickstart/images link which works for images and i added in the description field to this.
See both bits of code below on my portfolio-page.php:
<?php
/**
* Page template
*
*/
include("./head.inc");
echo $page->body;
//Display images if available
if(count($page->portfolio_images)) {
echo '<div id="gallery">';
$n = 0;
foreach($page->portfolio_images as $image) {
echo "<p><img class='photo' src='{$image->size(200,200)}' alt='{$image->description}' width='200' height='200' />";
echo "<br />{$image->description}</p>";
$n++;
}
echo "</div>";
}
//Display images if available
if ($page->portfolio_images) {
foreach($page->portfolio_images as $image) {
$thumbnail = $image->size(200,200);
echo "<p><a href='{$image->url}'><img class='photo' src='{$thumbnail->url}' alt='{$image->description}' /></a>";
echo "<br />{$image->description}</p>";
}
}
include("./foot.inc");
and link to the live page:
http://www.alexcreed...portfolio-page/
You can see where those images are not rendering there's just a double description. Does anyone know why?
Also in Formailer's code what do these bits do: $n = 0; $n++;
I am starting to understand the other parts .
Thanks,
Alex
#5
Posted 12 December 2011 - 06:26 AM
<img class="photo" src="4571168461_44f687f4e4_b.200x200.jpg" alt="Image one description" width="200" height="200">
src should be something like this: /site/assets/files/1001/4571168461_44f687f4e4_b.200x200.jpg
#6
Posted 12 December 2011 - 06:47 AM
I think your image src line needs a "->url":
src='{$image->size(200,200)->url}
That way it'll pick up the path to the smaller image.
Regards
Marty
#7
Posted 12 December 2011 - 06:48 AM
I think your image src line needs a "->url":
src='{$image->size(200,200)->url}
My mistake, sorry! I updated my example.
Now it seems to work on your site.
$n is just a counter, which is zero before we begin. $n++ is just increasing it with one.
You actually don't need it, but it can be nice if you want to echo the picture number, something like this:
<?php
echo "Image $n: {$image->description}";
Which would result in: Image 1: Description of image 1
Image 2: Description of image 2
etc.
/Jasper
#11
Posted 12 December 2011 - 05:23 PM
More examples are available here: http://processwire.c...k-start/images/
I'd forgotten those tutorials were there. The only way to get to them is through the search engine (I think). These were written by my brother-in-law back when PW 2.0 was new (nearly a year ago). He never was able to finish them because he got a new job that takes all his time. These tutorials may not be totally applicable anymore (I haven't read them all yet). But I'd be interested to hear if you guys think they are helpful and if we should update and finish them. Now that they've turned up again, I'm going to read through them in more detail here.
#12
Posted 12 December 2011 - 05:52 PM
I've actually got some time tomorrow evening to look at this if you don't get time before then
#14
Posted 13 December 2011 - 01:03 AM
I especially liked the idea of showing how to combine several things, like in the image tutorial: show how to display images, show how to make thumbnails and to finally an example on combining these things into something that is useful for many.
/Jasper
#15
Posted 13 December 2011 - 09:00 AM
I've actually got some time tomorrow evening to look at this if you don't get time before then
Thanks, that would be great if you have time to take a look. If you find anything that you don't think is right, feel free to change it too.
Thanks,
Ryan
#17
Posted 13 December 2011 - 06:10 PM
Also you can use ->width(100) or ->height(n) respectively doing the same as keeping the ration either on width or height
While at it, Ryan how is the compression setting when using API to scale? Is there way to set it?
@somartist | modules created | support me, flattr my work flattr.com
#20
Posted 14 December 2011 - 09:43 AM
While at it, Ryan how is the compression setting when using API to scale? Is there way to set it?
The /wire/core/ImageSizer class accepts a quality setting, but the Image fieldtype doesn't use it at present, so it just defaults to a quality setting of 90 (out of 100). My experience has been that that's ideal for most cases. But this would be one good future improvement to make this configurable.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users













