Jump to content

image thumb access?


bwakad
 Share

Recommended Posts

I have been reading too much to find the answer...

What I now am building is a way for users to upload their avatar. So an image field added to the user template.

  1. Question:
    In site/assets/files I see there are thumbs created. Were are these sizes set.
     
  2. Question:
    If I loop through my user template pages, ususally one get to the image like $page->image (single). But how do I get to the thumb?
Link to comment
Share on other sites

In your template, call $page->image->size(80, 100) to get an image with 80px width and 100px height. It's all explained at the images page.

If you've turned on the option for specific image field to display thumbnails in the page editor, ProcessWire will automatically generate some thumbnails (imagename.0x100.jpg), but that doesn't mean anything for you, really.

Link to comment
Share on other sites

I have this code for now which seems to NOT work in the foreach, but when I use the direct path, it does???

I added the field named "image", type set to "image", only allow 1, and attached it to the user template.

$test = $pages->find("template=user");

echo "<ul>";

    foreach($test->image as $image) {
        $thumb = $image->width(300);
        echo "<li><img src='{$thumb->url}' width='$thumb->width' /></a></li>";
}

echo "<li><img src='/site/assets/files/1013/cnn-logo.jpg'></li>";

echo "</ul>";

Link to comment
Share on other sites

Well,  changed the code to this which seems to work:

$test = $pages->find("template=user");
    foreach($test as $member) {
        if($member->image) echo "<img src='{$member->image->url}' />";
    }

But don't really see the difference...

If I use this:  $thumb = $member->image->size(100,100); inside the foreach(), is that good, or do I use it somehow outside?

Link to comment
Share on other sites

If you need an image (or thumb) for each individual member, then using it within foreach loop is just fine.

Also, size() creates the thumb, but you'll still have to call the URL of said thumb; $member->image->size(100,100)->url etc.

Link to comment
Share on other sites

Got it.

I get all the related stuff by only requesting template=user, and go for the image, but is there a chance someone could hack in one way or another and get to other fields in this template, since the template holds username, email, pass ???

$mymembers = $pages->find("template=user");
    foreach($mymembers as $member) {        
        if($member->image) {
            $thumb = $member->image->size(100,100);
            echo "<li><img src='{$thumb->url}' /></a></li>";
        }
    }
Link to comment
Share on other sites

I now, used the slick slider. There is only one issue with the slider: In the initialisation one has to say how many are visible. And space in between get's calculate automatically. This produces a strange layout in foundation. So inside the div for the slider I used a panel, and inside of that 2 columns. Looks pretty cool, and the slider just slide 2 columns at a time!

post-2177-0-50320500-1408123464_thumb.pn

But now I face another challenge and I think I have to start another topic for that ? (admin/mod can tell me)

profile template hold fields such as location, interests.

while this slider get it's values from the user template, image and username.

How do I get fields related to eachother from 2 different templates?

- edit -

Just moved the image field to the member-profile template which is actually better. Then I just have to reference one template for displaying members. And user template only holds the information regarding register and login.

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...