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

Trying to resize logo

Started by Muut Archive 11 years ago · 15 replies · 866 views
11 years ago

I'm using the machine theme and trying to resize the logo using meta files. It says here that I can use meta files to to resize the image but its not working.

Any ideas?

11 years ago

You are welcome, you can post on gist or pastie you template page where you have the code for resize the logo?

Thanks!

11 years ago

in the machine theme the logo is generated with logo_url from theme config or logo.png inside /theme_dir/assets/images/logo.png

TWIG
<a href="{{ base_url }}"><img src="{{ theme_config.logo_url | default(theme_url ~ '/assets/images/logo.png') }}" alt=" " /></a>

you can change the size of the logo manually or change the value for css.

11 years ago

I've changed the logo by copying the machine.yaml file to user/config/themes/machine.yaml.

Here is the custom machine.yaml file. The logo has changed but not the size. I put the logo and the meta file in user/images/ .

Can you tell me why the meat file doesn't work?

11 years ago

The metadata to set defaults on images needs to be specific to the actual image file, so in this case logo.png.meta.yaml located along side the logo.png file. However, resizing of media is only available for page media, so media associated with the page.

In this machine theme, the image is located in the theme's assets/images folder, and so it just a regular image, and not available for manipulation with Grav's page media functions.

11 years ago

If you wanted to be able to manipulate the image directly you could create an user/pages/images folder in your page structure, and put the image in there.

Then you could have your meta.yaml file in there also as described above. Then you could reference the image like so:

TWIG
<a href="{{ base_url }}"><img src="{{ base_url_absolute}}/images/logo.png" alt=" " /></a>

Not tested, but that should work :)

11 years ago

Nice @rhukster i waiting your reply because i not have idea how to use media file in the global template, thanks to do it :)

11 years ago

In this line

YAML
<a href="{{ base_url }}"><img src="{{ theme_config.logo_url | default(theme_url ~ '/assets/images/logo.png') }}" alt=" " /></a>'

What does this do?

YAML
theme_config.logo_url 
11 years ago

And yes, I have set the logo in the theme's config file. It is loading, so how can I resize it?

I want to resize it like this because then I can change the logo and not worry about the size.

11 years ago

yeah because if in anytime i want change the theme name i can without need to change all reference in the themes file.

TXT

theme_config = config.themes.machine
---
11 years ago

Put your logo into /pages/images/logo.png and change in the theme the link to logo to this:

TWIG
<a href="{{ base_url }}"><img src="{{ base_url_absolute}}/images/logo.png" alt=" " /></a>

Now the image it's processed by media with Grav.

11 years ago

It doesn't work. I still can't get it to resize.

11 years ago

Did you read my post above? I explained that the image would have to be a page media image to be able to use the resizing capability. I even gave some example code of how you would change the URL to point to a image that was inside the pages folder structure, and therefore a valid media file.

You are still pointing to an image in the theme. This is not page media, its just a regular image, and therefore does not support resizing.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1321 9 years ago
Archive · by Muut Archive, 9 years ago
2 916 9 years ago
Archive · by Muut Archive, 9 years ago
2 4047 9 years ago
Archive · by Muut Archive, 9 years ago
1 2921 9 years ago
Archive · by Muut Archive, 9 years ago
3 1105 9 years ago