Skip to content

Ascii art banner generated from an image #4647

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

Closed
wants to merge 3 commits into from
Closed

Ascii art banner generated from an image #4647

wants to merge 3 commits into from

Conversation

craigburke
Copy link
Contributor

Add new ImageBanner class that generates ascii art with color based on
an image file (banner.gif, banner.jpg or banner.png). There are
configuration settings that go along with this:

  • banner.image.dark: whether to invert image for a dark background.
    (default is false).
  • banner.image.max-width: maximum width in characters of banner
    (default is 72).
  • banner.image.aspect-ratio: correction to makes sure height is correct
    to accomodate the fact that fonts are taller than they are wide.
    (default is 0.5)

Add new ImageBanner class that generates ascii art with color based on
an image file (banner.gif, banner.jpg or banner.png). There are
configuration settings that go along with this:

- banner.image.dark: whether to invert image for a dark background.
  (default is false).
- banner.image.max-width: maximum width in characters of banner
  (default is 72).
- banner.image.aspect-ratio: correction to makes sure height is correct
  to accomodate the fact that fonts are taller than they are wide.
  (default is 0.5)
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 30, 2015
@craigburke
Copy link
Contributor Author

screen shot 2015-11-30 at 1 11 18 pm

Also, here's an example of the kind of amazing banners that can be generated with this.

@wilkinsona
Copy link
Member

Oh my! Thanks for the PR. Have you signed the CLA?

@craigburke
Copy link
Contributor Author

@wilkinsona yeah. I signed it last week.

@philwebb philwebb added for: team-attention An issue we'd like other members of the team to review and removed status: waiting-for-triage An issue we've not yet triaged labels Nov 30, 2015
@philwebb philwebb added this to the 1.4.0 milestone Nov 30, 2015
@philwebb
Copy link
Member

I've tagged this for 1.4 but also labeled "for team discussion" since I'm wonder if we shouldn't consider add such a critical feature to 1.3.x.

@spencergibb
Copy link
Member

👍

@OryxGazella
Copy link

This is the last thing stopping our team from adopting Spring Boot everywhere. Any chance of back porting it to 1.2.*?

@craigburke
Copy link
Contributor Author

@OryxGazella I'm shutting down all my current Spring Boot production apps until this is merged. I'll probably get fired but this is important and I need to stand on principal here.

@philwebb
Copy link
Member

@OryxGazella Spring Boot 1.3 has been out for weeks now, WEEKS! What are you still doing on 1.2?

@davidnortonjr
Copy link

I'm pretty sure Ratpack has supported this for 5-6 years, why is Spring stuck in the dark ages?

@danveloper
Copy link

Can confirm. Ratpack has supported this for 6.5 years. Spring Boot? More like "Enterprise Release Cycle Boot".

@philwebb
Copy link
Member

philwebb commented Dec 1, 2015

Such an unfair comparison. Ratpack is “asynchronous” & “non blocking” and as a result they can do everything faster. I think we need to consider the bigger picture here and look at how we can work together to create a standard.

@craigburke would you be able to draft a specification & create a TCK. I'm happy to donate my avatar to the project and I believe that this would make a fine default banner for all projects.

@philwebb
Copy link
Member

philwebb commented Dec 1, 2015

I almost forgot, we are going to need a way to also specify banners in XML!

@craigburke
Copy link
Contributor Author

@philwebb Draft a specification? Create a TCK? XML Banners (what would that look like)? What?

Let me know what you need and I can work on it.

@philwebb
Copy link
Member

philwebb commented Dec 1, 2015

@craigburke I'm imagining some sort of cross between Docbook and WSDL.

@wilkinsona
Copy link
Member

If we're going with XML, we ought to ensure it's as concise as possible. A single pixel banner's only 16 lines:

<spring-boot-banner>
    <pixels>
        <pixel>
            <location>
                <x>0</x>
                <y>0</y>
            </location>
            <color>
                <red>255</red>
                <green>255</green>
                <blue>255</green>
                <alpha>0</alpha>
            </color>
        <pixel>
    <pixels>
</spring-boot-banner>

@craigburke
Copy link
Contributor Author

This all seems very reasonable. I'll have it done within the hour.

@OryxGazella
Copy link

OryxGazella commented Dec 1, 2015

@craigburke Some things are more important than steady employment.

@philwebb I'll change our CI to deploy a new version of all of our apps as soon as there's a new stable version of any dependency. What could go wrong? After people are used to the idea we could go do this with snapshot versions too.

@wilkinsona XML looks good, but you forgot the XML namespace. This is for the enterprise, after all...

@snicoll
Copy link
Member

snicoll commented Dec 1, 2015

@wilkinsona where is the XSD? This is so disappointing.

@craigburke
Copy link
Contributor Author

I'm just throwing the banner into <![CDATA[...]]> it's valid XML and that's all I really care about.

@craigburke
Copy link
Contributor Author

I would like to actually tweak this a bit so that WHITE (aka light gray) isn't matched quite as often. Ideally I'd want a light green in an image to match to BRIGHT_GREEN even if WHITE is technically a bit closer.

@htynkn
Copy link
Contributor

htynkn commented Dec 2, 2015

This is a real cool feature. 👍

@danveloper
Copy link

When can we expect the official spec for this? My enterprise needs this feature ASAP. Is anyone even working on the XML implementation over there? Please get serious about this.

@herder
Copy link

herder commented Dec 2, 2015

We are running a system in production which because of reasons can't easily be upgraded to 1.3.
Could this crucial feature please be backported to 1.1?

@alvarosanchez
Copy link

@craigburke do not forget to setup my "microservices infographic" as the default value

@philwebb philwebb removed the for: team-attention An issue we'd like other members of the team to review label Dec 2, 2015
@cbornet
Copy link

cbornet commented Dec 14, 2015

I have done mine adding springfox (swagger) to a fork of @joshlong project to get a nice UI.
You can check it here.Code here. Not sorry.
Note : invert/dark, width, aspect-ratio options available and using CIE94 algo

@Shredder121
Copy link
Contributor

Where's my recognition? 😉

@cbornet
Copy link

cbornet commented Dec 14, 2015

@Shredder121 You can PR. I will gladly merge 😄 !

@Turbots
Copy link

Turbots commented Dec 14, 2015

@cbornet I prefer Spring REST Docs over Swagger, will update my version tonight 😊

@cbornet
Copy link

cbornet commented Dec 14, 2015

Unless I am mistaken, there is no "try it" button in spring rest docs to generate the banner

@danveloper
Copy link

if only we could get the developer of spring rest docs involved... // @wilkinsona

@michael-simons
Copy link
Contributor

Oh dear… Spring Boot 1.4 will be released together with JDK 9. All resources bound to banner.xxx by the end of the year ;)

Am 15.12.2015 um 14:58 schrieb Dan Woods notifications@github.com:

if only we could get the developer of spring rest docs involved... // @wilkinsona


Reply to this email directly or view it on GitHub.

@snicoll
Copy link
Member

snicoll commented Dec 15, 2015

I am ok with jokes @michael-simons but let's not push it too hard please :) You intend to write Spring Boot 2.0, right? 😃

@nealeu
Copy link

nealeu commented Dec 17, 2015

Hey @jhoeller, it looks like there's a bit if spare resource for some of those 'might not land' features for Spring 5.

I'm begging... Please, please, you have to find them something to do before they add a WebGL world full of ASCII art, live updated over a web socket each time someone converts an image on Josh's Boot app

@michael-simons
Copy link
Contributor

Hmmmm… WebGL Banner. inside sobering homer image here

@nealeu
Copy link

nealeu commented Dec 17, 2015

Oh yes... WebGL from animated GIFs http://giphy.com/gifs/loop-the-simpsons-tired-12GbJUnssN6NTa.

@cbornet
Copy link

cbornet commented Dec 17, 2015

fp2

@Shredder121
Copy link
Contributor

@cbornet Could you maybe side-by-side the original and CIE94 algorithm using that picture?
I'd like to know how it works with low luminance.
(There are infinite pictures with very vibrant colors, but this one is also a good test subject)
Also .. facepalm

@philwebb philwebb modified the milestones: 1.4.0.M1, 1.4.0 Jan 7, 2016
@haskovec
Copy link

Is this going to merge anytime soon? I tried the 1.4.0.BUILD-SNAPSHOT just now and realized that it wasn't in yet.

@wilkinsona
Copy link
Member

@haskovec It's assigned to 1.4.0.M1 so it should be merged some time before that milestone is released. The currently planned date for that release is 24 February.

@wwadge
Copy link
Contributor

wwadge commented Feb 24, 2016

Maybe also include a quick text-banner generator:

public static String toBanner(String banner) {
        System.setProperty("java.awt.headless", "true");
        BufferedImage image = new BufferedImage(144, 32, BufferedImage.TYPE_INT_RGB);
        Graphics g = image.getGraphics();
        g.setFont(new Font("Courier New", Font.PLAIN, 11));
        Graphics2D graphics = (Graphics2D) g;
        graphics.drawString(banner, 6, 24);
        ByteArrayOutputStream bas = new ByteArrayOutputStream();
        try {
            ImageIO.write(image, "png", bas);
            StringBuilder result = new StringBuilder("\n");

            for (int y = 0; y < 32; y++) {
                StringBuilder sb = new StringBuilder();
                for (int x = 0; x < 144; x++) {
                    sb.append(image.getRGB(x, y) == -16777216 ? " " : image.getRGB(x, y) == -1 ? "#" : "*");
                }
                if (sb.toString().trim().isEmpty()) {
                    continue;
                }
                result.append(sb).append("\n");
            }
            bas.close();
            return result.toString();
        } catch (IOException e) {
            log.error("Unable to print out banner", e);
        }
        g.dispose();
        return "(error printing banner)";

    }

Example:
System.out.println(toBanner("Hello"))

prints out:


      ### ###         ##     ##                                                                                                                 
       #   #           #      #                                                                                                                 
       #   #   ###     #      #     ###                                                                                                         
       #####  #   #    #      #    #   #                                                                                                        
       #   #  #####    #      #    #   #                                                                                                        
       #   #  #        #      #    #   #                                                                                                        
      ### ###  ####  #####  #####   ###                                                                                                         

Also perhaps include a way to show the banner at the end of context loading to show up as a signal that the app is ready.

@philwebb philwebb modified the milestones: 1.4.0.M1, 1.4.0.M2 Feb 26, 2016
@philwebb philwebb self-assigned this Apr 8, 2016
philwebb pushed a commit that referenced this pull request Apr 8, 2016
Add ImageBanner class that generates color ASCII art based on an image
file (banner.gif, banner.jpg or banner.png).

See gh-4647
philwebb pushed a commit that referenced this pull request Apr 8, 2016
Support CIE94 color distance calculations for improved ImageBanner
rendering. Based on code originally developed by Michael Simons and
added with his permission.

See gh-4647
philwebb added a commit that referenced this pull request Apr 8, 2016
Refactor several aspects of the ImageBanner:

- Extract a few new classes and methods from the previous code
- Directly encode ANSI rather than using `${}` properties
- Rework the scaling algorithm to prefer a fixed width
- Allow ImageBanner and TextBanner to be used together
- Rename several of the `banner.image` properties
- Add support for a left hand margin
- Add property meta-data

See gh-4647
@philwebb philwebb closed this in d058ddb Apr 8, 2016
philwebb added a commit that referenced this pull request Apr 8, 2016
* image-banner:
  Add image banner documentation
  Rework ImageBanner Support
  Add ImageBanner color distance calculation
  Support image based banners
@philwebb
Copy link
Member

philwebb commented Apr 8, 2016

This is now merged. Thanks for one of the most important pull requests in the history of the project!

@wilkinsona
Copy link
Member

A source at Thoughtworks tells me that this pull request was instrumental in Boot moving to adopt. Thank you for saving the project from oblivion.

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.