Show a cropped image in lovelace

Hi. I use this: https://www.yr.no/nb/innhold/2-2673730/meteogram.svg

And i want it to crop the image to show what’s in the red box, like this.

I use the camera component today and i tried the camera proxy to crop the image but it won’t display anything. Maybe because the image is a .SVG

I used this for a long time but now, since 1 feb. they changed it, making it bigger with logos and stuff.

I tried the picture-glance card. Changing the aspect ratio almost does it but if i remove logos at the top it cut the image too much in the buttom. I could need to reposition the image in the card.

Of course the image needs to refresh in an interval.
Any ideas?

Make a shell script (yr-svg.sh) in your config-folder with the content like this:

curl -o /config/www/met2.svg https://www.yr.no/nb/innhold/2-2673730/meteogram.svg
sed -i -e 's/height="391"/height="270"/g' -e '56,121d' -e 's/translate(0, 84.86)/translate(0, 0)/g' /config/www/met2.svg
mv /config/www/met2.svg /config/www/met3.svg

It downloads the svg file. Removes the lines in the svg file that contains “logos and stuff” and moves the rest to position 0,0.
Then it renames the modified file to a new name.

configure a shell_command integration in you configuration.yaml:

shell_command:
  get_yr_svg: bash /config/yr_svg.sh

Make an automation that runs the shell script every 30 minutes.

alias: Get YR
description: ''
trigger:
  - platform: time_pattern
    minutes: /30
condition: []
action:
  - service: shell_command.get_yr_svg
    data: {}
mode: single

Make a generic camera:

http://127.0.0.1:8123/local/met3.svg

Use the camera in a picture-entity-card.

2 Likes

This is really cool. I would like to use it for a 2560*1920 jpg file, but not sure I understand how the parameters work. How do I cut off 30 % in each side and the bottom 50 %?

type: picture-elements
elements:
  - type: image
    image: /local/images/test/test_mask_2.png
    style:
      top: 1%
      left: 0%
      transform: translate(0,0)
image: https://www.yr.no/nb/innhold/2-2673730/meteogram.svg

Create PNG file of big size (for instance, 1920x1080).

In a masonry view:

In a Panel view:

in which browser do you get that result ? … i get a white picture

… and/or

… beside , when one use “picture-element”, a “vital” feature is “lost” … clicking on the picture wont "expand# the pic … it just complaining about “no entity provided for more-info dialog”, so your basically “stucked” with a “small” version in a card, of a high resolution weather-info-picture , which suppose to update, frequently

Did you create a proper PNG?
It is a rectangle with a transparent gap - to hide top & bottom parts.

Expanding an image by a tap_action is not supported by any conventional card.
As for “no entity provided …” - this may be fixed by “none” for “tap_action”.

1 Like

when i only use 1% top it gives me a (almost) white pic … if i add 30% left ( as u see) it shows me 30& from the left, and

Please check your PNG file - it must be like this one (with a transparent gap):

1 Like

LOL, i just made a “blank” 1920x1080 :joy: … that explain the weird behavior

The main idea of my proposal was:
– place the SVG on the card, let it will the whole card;
– then overlap it by a PNG mask (should be of bigger size) - to hide the top & bottom parts.

There is one more method:
– place the SVG on the card;
– shift it to the top (negative top position);
– set the card’s height:

type: picture-elements
elements:
  - type: image
    image: https://www.yr.no/nb/innhold/2-2673730/meteogram.svg
    style:
      top: -13%
      left: 0%
      transform: translate(0,0)
image: /local/images/test/blue.jpg
card_mod:
  style: |
    ha-card {height: 175px !important}

image
but this method is not good, depends on the current card’s size…

ok, now i get how it was “placed”, but any way seems not ideal, to me, i’ve had this url-pic as a temporary solution, until i have time to find a better.
… i like yr.no, as it also seems to be most accurate where i live, just haven’t looked into a way of getting their “info” into a graph-card, so i also just have it as a pic/stream

  1. I prefer a graph, with transparent background (using the card-background)
  2. haven’t found a way to get the precipitation into nice thin stables

using the history-card for the wind-direction, temp and precipitation graphs works.

Here is my “modded” custom:weather-chart-card , which i can’t seems to get to “deep” into , partly i wanted to make thinner stables for the precipitation , and also change color of the “line-graphs” etc.

I also want to cut camera image

I tried to find this solution about a year ago and finally understood how to achieve what I was looking for when reading your reply.

My application: take a floorplan image provided/updated by my robot vacuum and zoom in so the blank area outside of the floorplan is cropped out of view.

Hey, did you happen to find a solution?

Hi @Mosher, yes, I was able to find a solution. I use a picture-elements card. The trick is not to worry about the image_entity property of the picture-elements card as that essentially becomes the background for that card and does not support styling (only the elements can be styled).

Here is what I do.

  1. I set the image_entity property to the image that I need to zoom in on or move. This is because the image_entity is a required property and cannot be blank.
  2. Then I add a single image element with the same image and apply a style to it to achieve the zoom and placement that I am looking for.

Here is an example:

type: picture-elements
image_entity: image.roborock_q5_first_floor
elements:
  - type: image
    entity: image.roborock_q5_first_floor
    style:
      width: 180%
      height: 180%
      left: 50%
      top: 50%
    tap_action:
      action: none

There is a ton more that can be done with the picture-elements card. Full documentation here: Picture elements card - Home Assistant (home-assistant.io)