Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image element created #226

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Image element created #226

wants to merge 3 commits into from

Conversation

jmcasimar
Copy link

This is my first proposal to solve #208

I am working to add dynamically an image to the header, but is not ready yet.

@jmcasimar
Copy link
Author

The latest commit actually allows add an image encoded as base64 string to header menu in the left corner.

The example sketch creates 2 images:

  • In menu header the logo is define as AutoConnectConfig new property named logo. By default this property is an empty String and it does not affect the menu (It looks like always), but when you define this property it creates the image in the left corner of the menu header.
  • The second image is added as a new AutoConnect Element and has support to read json property from SPIFFS.

AC_SS

This code has some limitations, for example the image in the header by now is fixed to 60x60, this works when the aspect ratio of the image is 1:1 but it can be easily defined as a new AutoConnectConfig property. Also the title of the menu is moved to the center by the image, I think that this aspect could be much better, but this shows that is possible to solve #208

@Hieromon
Copy link
Owner

Thank you for the PR.
Below is my frank view of this PR. I don't think there is a positive reason to add image-specific base64 as a common element. It is the whole thing for the entire PR that no measures have taken to reduce heap memory. Also, how it keeps the layout of the menu block in the AutoConnect menu.

  1. Instance size included in AutoConnectConfig is too large.

  2. HTML native code in the header is too large. It may become insufficient for the heap and cannot be generated by PageBuilder. As a result, the page cannot be displayed. I think that it is necessary to consider on PageBuilder to make the effective actually.

  3. AutoConnectImage can be easily replaced by AutoConnectElement. I can't find particularly utility value to generate the <img> tag.
    Rather, it should be more useful to have a <img> element with the <a> tag as the UI like the switch button image generation for the ESP modules as a sensor device.

  4. ACImage with JSON does not work.

    {
      "name": "logo",
      "type": "ACImage",
      "value": "iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAAgVBMVEX///8AAAIAAAC4uLjv7+/Ly8tAQEGRkZHX19ccHB0ODg/r6+u/v7+FhYbh4eGurq75+fl3d3htbW3d3d2oqKigoKCIiIg3Nze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NNEo3eZLVbra78pgzbRBCr0Xer1hsgQO+zMIYRQfeFP+v4Kyl8vxQPQuAAiclDEZX8QbWYmqJEMZCz3MYwhWOdeOERadlZQnhSzXzxpvgJIHByFcmLLo6W93Xlku4a5ewJVu6/jmERZ3qZb360KzlPKNlwueWCKGBzLGlsB0aDmR9ViIkfwsCliaEBZPTEuDuN0PvPDb1gxkfpbhUeJNEWULw7tc8a/anUI8fDTI/gzylKSUXngr7YUsToq0Y5h4J3FnAVWOS3XV8uJ3G6EWbgBtNI+8Cskt4KdoQj8VtUp5+6I4h8FbiulvdLe/6gsNNQ3uHlbToEFIny4STYoUI26vJ21FEtndfgoOd+vVB5DCte1zBNiHsErUtLIA3lc6VJOv7vGEhaua2aKZc+0CGdcJnWAMHKkQ0Ua4QB0GS/fMWZwSQHeSDEWkTRZjxtZVStVNB+GietKlk8oYAB1W7ivCwSZSeViV+9OdwXGYzUjXCZzzcD8C7DU83aSW/6tHEq8HXRu7tjbwTbaQFDLKfLQ6Hw3Yl78cotaUG6tE0My7hEG7khGX602a2m1Q/95Uz9S9+3qryKdmbOQdJPt6qNsJ1XvKFd81VP8tdALE6YPoCc23abXmigIwtheaB7KuPuOe5hEUtWJ2YCpucrYm15r25P1/RcUStuBjzvTYfpO7xYHMNKbGzs2b0FhogSpGT6OK5boyFMzGp9f4w1fAh0wVGmjVwdnY5mepUZnTaQJyo+fYV/bxfj81HWKihhuK1zacbfxfJ35yaC8DTjFzsy/7LEfZfjrD/coT9lyPsvxxh/+UI+y9H2H85wv7LEfZf/xXh/jT+hTo9CsLf/8bj36z/hPB3a+QtL8PfrEaD4Ts5OTlp9A9tuM3Sf39ZwAAAAABJRU5ErkJggg=="
    },

    Results (loadElement error):

    [AC] Type of logo element mismatched
    
  5. This PR code is incomplete. I present the results of testing I have included AutoConnectConfig::logo with Elements.ino. It cannot display the logo image.

    config.logo = "iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAAgVBMVEX///8AAAIAAA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jG54amkVqmHVLsdPEM4JcWnLTV6/JwBGfRZqV43ypW2Qu3QAOz6oq9X8J7pGL+oO7oOoXldBswejRu9+dYjMtjNNEo3eZLVbra78pgzbRBCr0Xer1hsgQO+zMIYRQfeFP+v4Kyl8vxQPQuAAiclDEZX8QbWYmqJEMZCz3MYwhWOdeOERadlZQnhSzXzxpvgJIHByFcmLLo6W93Xlku4a5ewJVu6/jmERZ3qZb360KzlPKNlwueWCKGBzLGlsB0aDmR9ViIkfwsCliaEBZPTEuDuN0PvPDb1gxkfpbhUeJNEWULw7tc8a/anUI8fDTI/gzylKSUXngr7YUsToq0Y5h4J3FnAVWOS3XV8uJ3G6EWbgBtNI+8Cskt4KdoQj8VtUp5+6I4h8FbiulvdLe/6gsNNQ3uHlbToEFIny4STYoUI26vJ21FEtndfgoOd+vVB5DCte1zBNiHsErUtLIA3lc6VJOv7vGEhaua2aKZc+0CGdcJnWAMHKkQ0Ua4QB0GS/fMWZwSQHeSDEWkTRZjxtZVStVNB+GietKlk8oYAB1W7ivCwSZSeViV+9OdwXGYzUjXCZzzcD8C7DU83aSW/6tHEq8HXRu7tjbwTbaQFDLKfLQ6Hw3Yl78cotaUG6tE0My7hEG7khGX602a2m1Q/95Uz9S9+3qryKdmbOQdJPt6qNsJ1XvKFd81VP8tdALE6YPoCc23abXmigIwtheaB7KuPuOe5hEUtWJ2YCpucrYm15r25P1/RcUStuBjzvTYfpO7xYHMNKbGzs2b0FhogSpGT6OK5boyFMzGp9f4w1fAh0wVGmjVwdnY5mepUZnTaQJyo+fYV/bxfj81HWKihhuK1zacbfxfJ35yaC8DTjFzsy/7LEfZfjrD/coT9lyPsvxxh/+UI+y9H2H85wv7LEfZf/xXh/jT+hTo9CsLf/8bj36z/hPB3a+QtL8PfrEaD4Ts5OTlp9A9tuM3Sf39ZwAAAAABJRU5ErkJggg==";
    portal.config(config);
    portal.begin();

    ACImage

@jmcasimar
Copy link
Author

Thanks for your time to test it,

All the time I knew that memory could be a problem because base64 generates too large strings.

At first, I made this PR knowing that my methods would be poor in stability and perfomance. I´m relatively new in C++ and there are some parts of the code that I do not understand yet, but I made the PR for 2 reason:

  • Probe myself that what I propose is possible in someway, and force myself to read, try to understand, modify and learn with your code.
  • Ask for your opinion, and get some feedback to continue working this idea.

With that in mind, I share your view about the PR. I do not even know what AutoConnectElement is capable to do. I do not have enough time as I would like, but I will continue working on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants