[Lib] ImageMessage (v2.1)- Send images to players via the chat!

Discussion in 'Resources' started by bobacadodl, Dec 10, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    bobacadodl

    <font color="#33cccc">ImageMessage v2.1</font>
    [​IMG]

    Send images to players via the chat bar!
    Now supports .GIFs!
    Source

    Original
    (old version, static methods)

    Example Usage:
    Code:java
    1. BufferedImage imageToSend = ImageIO.read(this.getResource("creepermap.png"));
    2. new ImageMessage(
    3. imageToSend, // the bufferedimage to send
    4. 8, // the image height
    5. ImageChar.MEDIUM_SHADE.getChar() // the character that the image is made of
    6. ).appendText(
    7. "",
    8. "",
    9. "",
    10. "Thatssss a",
    11. "niccceee house",
    12. "you've got there"
    13. ).sendToPlayer(event.getPlayer());


    creepermap.png
    [​IMG]


    Result:

    [​IMG]
    Notes/Additional info
    * Tip: make the player unable to receive chat messages for a few seconds after you send the image. Here's an example on how to mute players: https://gist.github.com/bobacadodl/7905691
    * If you want more accurate colors, only use images with color codes from http://minecraft.gamepedia.com/Formatting_codes Here's a <Edit by Moderator: Redacted mediafire url> palette[/url].
    * This library is based off of an idea from http://imgur.com/a/X3gzV
     
    Last edited by a moderator: Mar 21, 2017
  2. Offline

    Developing

  3. Offline

    NinjaWAffles

    This looks really good. Good job. :)
     
  4. Offline

    devilquak

    My god, this is amazing.
     
  5. Offline

    ArthurMaker

    awesome, dude!
     
  6. Offline

    DSH105 Retired Staff

    No way! ;o
    That's awesome :)
     
  7. Offline

    Aperx

    This is pretty sick...
    the things you can do with bukkit just keep expanding! :)
     
  8. Offline

    Ad237

    Nice job dude! This is amazing!

    Just had a thought. Would it be possible to do this in the lore of an item? Thanks.
     
  9. Offline

    Garris0n

    Yes
     
  10. Offline

    Ape101

    Apparently theres no method getResource? any ideas?

    EDIT: Nevermind xD needed to add my instance
     
  11. Offline

    BungeeTheCookie

    bobacadodl This is beautiful. You are a boss.
     
  12. Offline

    chasechocolate

    Wow, pretty neat! Never knew this was possible :confused:
     
  13. Offline

    Skyost

    bobacadodl Can we expend the max size ?
    EDIT : Yes ! :D
     
    GrandmaJam likes this.
  14. Offline

    theyanay5

  15. Offline

    bobacadodl

    Wow, neat idea! To do this just do something like this. (untested, but should work)

    Code:
    ItemStack i = new ItemStack(Material.STONE,1);
    ItemMeta im = i.getItemMeta();
    ChatColor[][] colors = ImgMessage.toChatColorArray(image, height);
    String[] lines = ImgMessage.toImgMessage(colors, ImgMessage.ImgChar.MEDIUM_SHADE.getChar());
    im.setLore(Arrays.asList(lines));
    i.setItemMeta(im);
     
    GrandmaJam and Skyost like this.
  16. Offline

    Yonas

    1) keep up this greate work :)
    2) Is it possible to use RGB Colors, not only the Minecraft Colours?
    Show Spoiler
    [​IMG]

    real Skin:
    Show Spoiler
    [​IMG]
     
  17. Offline

    Skyost

    Yonas I do not think so. It uses ChatColors ;)
     
  18. Offline

    bobacadodl

    No, this is a known issue :(. The messages in the chat can only use minecraft ChatColors, so it rounds each color to the closest chatcolor. If you want more accurate results, use images made up of the chatcolors.

    Here's a quick palette I made:
    [​IMG]
     
    GrandmaJam likes this.
  19. Offline

    Skyost

    bobacadodl
    Code:java
    1.  
    2. public static String[] appendTextToImg(String[] chatImg, String... text) {
    3. for(int y = 0, x = 0; y < chatImg.length; y++) {
    4. while(text.length > x && chatImg[y].length() < ChatPaginator.AVERAGE_CHAT_PAGE_WIDTH) {
    5. chatImg[y] = chatImg[y] + " " + text[x];
    6. x++;
    7. }
    8. }
    9. return chatImg;
    10. }
    11.  

    Try it like this ;)
     
    DSH105 and bobacadodl like this.
  20. Offline

    hawkfalcon

  21. Offline

    bobacadodl

    Skyost
    Haven't tested that, but it looks like it will center the text on the page. Is that correct?
     
    Skyost likes this.
  22. Offline

    Skyost

  23. Offline

    ccrama

    bobacadodl Is there any way to more accurately convert the colors to the present pixel colors? The images tend to be mostly gray, with little color at all :(. This is supposed to be my skin (same as profile pic)
    [​IMG]

    Also, is there any way to easily edit the size from 10x10 to 8x8? I changed this line

    if (width > 10) width = 10;
    to
    if (width > 8) width = 8;
    and it still displays as 10x10...
    Thanks for this great asset though!
     
  24. Offline

    bobacadodl

    ccrama
    Did you read the usage? One of the parameters in the image height. Just change that to 8...
    Also the inaccurate colors is a known issue. I'm looking for a better method for color matching.
     
  25. Offline

    ccrama

    bobacadodl wow, totally missed that. Stupid me. And sounds good! Also, I have no experience with java images/color of any kind, but would adding more contrast before you check the colors return a stronger match to the minecraft colors? If so, that would probably be a simple solution to the issue.
     
  26. Offline

    bobacadodl

    ccrama
    I'll try that and see how it turns out :)
     
  27. Offline

    ccrama

    bobacadodl Great, hope it works! This would be an awesome addition to my plugin. When a user scores, show the huge head and say CCRAMA SCORED!

    FYI, simple method to get a players head in chat. Do this:
    1. Use this to display the image, I use mine after an event. Use e.getPlayer() to get the player variable

    Code:java
    1.  
    2. try {
    3.  
    4. URL url = new URL("[URL]https://minotar.net/avatar/[/URL]" + player.getName() + "/8.png");
    5. //BUKKIT forums wont let me remove the URL tags, make sure you do that.//
    6. ImgMessage.imgMessage( e.getPlayer(), ImageIO.read(url), 8, ImgMessage.ImgChar.BLOCK.getChar(), BLOCK, DARK_SHADE, MEDIUM_SHADE, or LIGHT_SHADE "CCRAMAS HEAD"); } catch (IOException e) { e.printStackTrace(); }


    2. Change this line in your imgMessage class

    PHP:
     BufferedImage resizedImage = new BufferedImage(widthheightoriginalImage.getType()); 
    to

    Code:java
    1. BufferedImage resizedImage = new BufferedImage(width, height, 6);
    You will get errors trying to get a web image without this change.


    Will look like [​IMG]

    Bukkit ruined my formatting/tabs. Please ignore the horrible formatting!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  28. Offline

    Skyost


    How about this one ?
     
    GrandmaJam likes this.
  29. Offline

    bobacadodl

    Nice, I'll try it out!

    Updated the post with the new algorithm! It works better for some images, but worse for others :eek:. Overall, I'd still say its better, so I've switched.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
    Skyost likes this.
  30. Offline

    Gater12

    Holy crap. This is amazing.
     
    glen3b likes this.
Thread Status:
Not open for further replies.

Share This Page