Trying to resize logo

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?

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

Thanks!

http://pastie.org/9854864

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

<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.

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?

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.

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:

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

Not tested, but that should work :slight_smile:

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

In this line

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

What does this do?

theme_config.logo_url 

theme_config.logo_url basically gets the value you have set in the theme’s config for logo_url setting:

https://github.com/nunopress/grav-theme-machine/blob/develop/machine.yaml#L4

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.

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

theme_config = config.themes.machine
---

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

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

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

ok thanks

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

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.