Added bird generator from the official project.

This commit is contained in:
Christian P. MOMON 2020-09-26 03:51:39 +02:00
parent 9f3ca8cb95
commit e40cd9d087
76 changed files with 247 additions and 0 deletions

View file

@ -0,0 +1,247 @@
/*
* Copyright (C) 2020 Christian Pierre MOMON <christian@momon.org>
*
* This file is part of CatGenerator, simple service statistics tool.
*
* CatGenerator is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* CatGenerator is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with CatGenerator. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.devinsy.catgenerator.core;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Random;
import javax.imageio.ImageIO;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class BirdGenerator.
*/
public class BirdGenerator
{
private static Logger logger = LoggerFactory.getLogger(BirdGenerator.class);
/**
* Builds the avatar.
*
* @return the buffered image
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public static BufferedImage buildAvatar() throws IOException
{
BufferedImage result;
String seed = RandomStringUtils.randomAlphanumeric(10);
result = buildAvatar(seed);
//
return result;
}
/**
* Builds the avatar.
*
* @param size
* the size
* @return the buffered image
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public static BufferedImage buildAvatar(final int size) throws IOException
{
BufferedImage result;
result = buildAvatar();
result = CatGeneratorUtils.resize(result, size, size);
//
return result;
}
/**
* Builds the cat.
*
* @param seed
* the seed
* @param size
* the size
* @throws IOException
*/
public static BufferedImage buildAvatar(final String seed) throws IOException
{
BufferedImage result;
if (StringUtils.isBlank(seed))
{
result = buildAvatar();
}
else
{
// Create an empty image.
result = new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB);
Graphics2D grapher = result.createGraphics();
grapher.setBackground(Color.WHITE);
grapher.clearRect(0, 0, 256, 256);
// Add stuff.
// Initialize the random generator.
Random generator = new Random(Integer.parseInt(DigestUtils.md5Hex(seed).substring(0, 6), 16));
drawImage(grapher, "tail", generator.nextInt(9) + 1);
drawImage(grapher, "hoop", generator.nextInt(10) + 1);
drawImage(grapher, "body", generator.nextInt(9) + 1);
drawImage(grapher, "wing", generator.nextInt(9) + 1);
drawImage(grapher, "eyes", generator.nextInt(9) + 1);
drawImage(grapher, "bec", generator.nextInt(9) + 1);
drawImage(grapher, "accessorie", generator.nextInt(20) + 1);
grapher.dispose();
}
//
return result;
}
/**
* Builds the cat.
*
* @param seed
* the seed
* @param size
* the size
* @return the buffered image
* @throws IOException
*/
public static BufferedImage buildAvatar(final String seed, final int size) throws IOException
{
BufferedImage result;
BufferedImage avatar = buildAvatar(seed);
result = CatGeneratorUtils.resize(avatar, size, size);
//
return result;
}
/**
* Generate cat logo.
*
* @param seed
* the seed
* @param target
* the target
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public static void buildAvatarFromPeeperCarrotWebsite(final String seed, final File target) throws IOException
{
URL source = new URL("https://www.peppercarrot.com/extras/html/2016_cat-generator/avatar.php?seed=" + seed);
FileUtils.copyURLToFile(source, target, 5000, 5000);
}
/**
* Builds the avatar to.
*
* @param target
* the target
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public static void buildAvatarTo(final File target) throws IOException
{
BufferedImage result = buildAvatar();
ImageIO.write(result, FilenameUtils.getExtension(target.getName()), target);
}
/**
* Builds the avatar to.
*
* @param size
* the size
* @param target
* the target
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public static void buildAvatarTo(final int size, final File target) throws IOException
{
BufferedImage result = buildAvatar(size);
ImageIO.write(result, FilenameUtils.getExtension(target.getName()), target);
}
/**
* Builds the avatar to.
*
* @param seed
* the seed
* @param target
* the target
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public static void buildAvatarTo(final String seed, final File target) throws IOException
{
BufferedImage result = buildAvatar(seed);
ImageIO.write(result, FilenameUtils.getExtension(target.getName()), target);
}
/**
* Builds the avatar to.
*
* @param seed
* the seed
* @param size
* the size
* @param target
* the target
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public static void buildAvatarTo(final String seed, final int size, final File target) throws IOException
{
BufferedImage result = buildAvatar(seed, size);
ImageIO.write(result, FilenameUtils.getExtension(target.getName()), target);
}
/**
* Draw image.
*
* @param grapher
* the grapher
* @param name
* the name
* @param index
* the index
* @throws IOException
* Signals that an I/O exception has occurred.
*/
private static void drawImage(final Graphics2D grapher, final String name, final int index) throws IOException
{
URL url = BirdGenerator.class.getResource("/fr/devinsy/catgenerator/core/images/cat" + name + "_" + index + ".png");
BufferedImage part = ImageIO.read(url);
grapher.drawImage(part, null, 0, 0);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 298 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 298 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 298 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 298 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 298 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 298 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 298 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 298 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB