Jump to content

Recommended Posts

Posted

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.'"/>';
}
Posted

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
Posted

Theres also a max width height setting to use to resize larger uploaded images if they're bigger.

Posted

Have a look under "Files":

$image Properties (in addition to those in $files)

Images extend Files, so you can use all the methodes / properties from $files.

  • Like 1

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
×
×
  • Create New...