Giter Site home page Giter Site logo

Comments (16)

JayXon avatar JayXon commented on May 29, 2024 2

yes, images in SVG works too

Leanify/formats/xml.cpp

Lines 267 to 275 in b5f2efc

const string kDataURIMagic = "data:";
if ((strcmp(attr.name(), "href") == 0 || strcmp(attr.name(), "xlink:href") == 0) &&
value.size() > kDataURIMagic.size() &&
memcmp(value.data(), kDataURIMagic.data(), kDataURIMagic.size()) == 0) {
DataURI data_uri(&value[0], value.size());
data_uri.SetSingleMode(true);
size_t new_size = data_uri.Leanify();
value.resize(new_size);
}

from leanify.

JayXon avatar JayXon commented on May 29, 2024

Good idea, I'll implement it when I have time.

However, there's a little technical problem.
For now, some of the html file are recognized by Leanify as xml file. Should I write a html parser or just use current xml library? Or, maybe just search for data:image/png;base64?

from leanify.

javiergutierrezchamorro avatar javiergutierrezchamorro commented on May 29, 2024

Thanks for your reply JayXon.

I would say that detecting data:image/png;base64 and data:image/jpeg;base64 would be enough. No matter if they are serialized inside and HTML or an XML, optimizing the encoded base64 data will still make it compatible with both markups.

from leanify.

Jaff2002 avatar Jaff2002 commented on May 29, 2024

Just search for "data:image/xxx;base64," (where xxx is gif, jpeg or png ** it might be with mixded, upper or lowercase) and the image will end with " ) or '
For this optimisation of images please add it's own option when Leanify is called to optimise images but not the entire html/css file (just for compatibility reasons). Thank you!

from leanify.

JayXon avatar JayXon commented on May 29, 2024

Searching is the easiest way to implement it. The only concern is that if the file is not html/js/css, but it also has data:image/png;base64 in it, we may corrupt the file.

from leanify.

javiergutierrezchamorro avatar javiergutierrezchamorro commented on May 29, 2024

To be honest I do not think that finding an ocurrence such as data:image/???;base64 would be probable in file types other than HTML, XHTML, or XML.

They can happen in server side scripts outputing HTML such as PHP, ASP.NET or JSP, but this will not corrupt the outputed HTML.

Anyway, agree making it an option so it can be disabled.

from leanify.

JayXon avatar JayXon commented on May 29, 2024

Well, for example, html is embedded inside of some binary format which has a field of the length of the html.

If I can't find a way to make sure I don't corrupt the file, then I'll have to make the option disabled by default.

from leanify.

javiergutierrezchamorro avatar javiergutierrezchamorro commented on May 29, 2024

Sounds fair making this option disabled by default. Or maybe it can be enabled if detected file extension is known to be safe such as HTML, XML, or XHTML, and left it disabled for PHP, EXE (where HTML could be a resource), ...

from leanify.

lorents17 avatar lorents17 commented on May 29, 2024

Good day!
I have long had the idea to do this project, where the system automatically searches for the image base64 files in HTML, CSS, XML / SVG and extracts them. The draft also easily integrate them into your files back. I think the right thing to do a separate project on this issue.
I have not found a project that could support such.

from leanify.

Jaff2002 avatar Jaff2002 commented on May 29, 2024

For images inside binary files (e.g. EXE files) replacing original image with optimised + space padding (until you reach same size as original image data) is best option but first you need to detect in wich kind of filetype you do the optimisation (htm/html.js.xml or binary).

from leanify.

JayXon avatar JayXon commented on May 29, 2024

I think I'll only enable this on file with known extension (html, htm, js, css, etc.).
Binary files won't be supported for this feature, even if I add space padding, it may still corrupt the file if it has checksum.

from leanify.

Jaff2002 avatar Jaff2002 commented on May 29, 2024

Thank you!

from leanify.

JayXon avatar JayXon commented on May 29, 2024

Please try out the latest nightly build.

from leanify.

Jaff2002 avatar Jaff2002 commented on May 29, 2024

It works! Test file (css inside) https://ebooks.adelaide.edu.au/o/orwell/george/o79a/o79a.epub

from leanify.

JayXon avatar JayXon commented on May 29, 2024

Cool, feel free to create another issue if there are bugs.

from leanify.

TPS avatar TPS commented on May 29, 2024

To clarify, did this implement optimizing supported embedded images inside SVGs (.svg images), or just in HTML/XML/&c files that have such in them?

from leanify.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.