Jump to content

Working with Images


casey
 Share

Recommended Posts

I'm attempting to make a photoblog type of site and was wondering if there's a clean way to get the image directory path when using the $image->size method.

The purpose of this is so the user can upload their large images, display as a thumbnail and click to view a medium version no taller than 800px within a modal.

As you can see, I've had to hardcode the site/assets/files directory. Is there another method?

(*the getThumb function refers to another installed module)

foreach($page->images as $image) {
    echo '<a href="site/assets/files/'.$page->id.'/'.$image->size('','800').'"><img src="'.$image->getThumb('thumbnail').'" alt="'.$image->description.'"/>';
}
Link to comment
Share on other sites

Hi casey,

You can use $image->url

foreach($page->images as $image) {
  $big = $image->size('', 800);
  $thumb = $image->getThumb('thumbnail');
  echo "<a href='{$big->url}'><img src='{$thumb}' alt='{$image->description}'/>";
}

The Cheatsheet is very handy to check methods and properties:

http://processwire.com/api/cheatsheet/

Cheers

  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...