Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

General

How to use the cropZoom() for img tags

Started by Duc 8 years ago · 5 replies · 972 views
8 years ago

I am using the Instagram plugin and have got it to display my images. The thumbnails are displaying in different sizes, however. I would like to use the cropZoom(700, 700) to set a fixed size for the thumbnails, but am failing.

Here is my twig file

TWIG
{% if feed %}
    {% for post in feed|slice(0, count)  %}
        <div class="columns item instagram">
            <div class="item-wrap">
            <a href="{{ post.link }}" target="_blank" >
                <img src="{{ post.image }}" alt="">
                <div class="overlay"></div> 
                                <div class="link-icon"><i class="icon-plus"></i></div>
            </a>
            </div>
        </div> 
    {% endfor %}
{% else %}
<p><b>
    Could not load the Instagram feed! Please contact the owner of this site.
</b></p>
{% endif %}
8 years ago

Hi duceduc,

I'm not sure you can do that, or want to do it if you could, because you would be saving the image on your server every time.

You can handle that with css tho:

CSS
.instagram .item-wrap { width: 700px }; /* you can have any width here (px, vw, %, etc.) */
.instagram .item-wrap a { width: 100%; height: 0; padding-top: 100% }
.instagram .item-wrap a img { width: 100%; height: 100%; object-fit: cover; }
last edited 11/30/18 by Dzibus Allmighty
8 years ago

Thanks for the reply. How do I add this css to the file?

8 years ago

In the _user/themes/<themename>/css/ folder, add a file instagram.css (or any name you like) and paste the above code in that file.

After that open the _user/themes/<themename>/templates/partials/base.html.twig file and add:

TWIG
{% do assets.addCss('theme://css/instagram.css') %}

in the {% block stylesheets %} at the top of the page

last edited 11/30/18 by Dzibus Allmighty
8 years ago

@Dzibus
Thanks again for the help. I have added your suggestion, but it's not quite resizing the way I want it.The theme I am using is the woo. I copy the same screenshot section of the theme.

At one point, the plugin was working fine and I didn't had to re-style the image. It worked with the existing css. The size was a bit smaller compared to the default, but it was equal and spaced out in size. There was an update to Instagram API and the plugin was updated. That is when the change happened.

I think to have a square layout, it has to be modify at the plugin. Something to do with Instagram api.

Here is the screen shot of before your css.

Here is a screenshot of after your css applied.

last edited 11/30/18 by Duc
8 years ago

Sorry for a late reply.
Based on the Git page of Instagram API you say you use, last update was a year ago, so I'm not sure what changed and broke your code.

Anyway, it sounds like you are not pulling the .css file that styles the grid (that would be layout.css in your theme), or you are missing some classes on elements.

Try putting:

TXT
<div id="screenshots-wrapper" class="bgrid-quarters s-bgrid-thirds cf">

in between if and for and close it with </div> between endfor and endif

if that doesn't work, I can't help you without looking at the rest of the code (sadly, I don't have time for that now).

Good luck.

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 101 16 hours ago
General · by pamtbaau, 22 hours ago
1 68 21 hours ago
General · by Andy Miller, 1 day ago
0 53 1 day ago
General · by Marcel, 12 months ago
6 361 5 days ago
General · by Duc , 6 days ago
3 49 6 days ago