Last active
July 21, 2017 17:01
-
-
Save aveao/1bfe45f2c6f2100702dd146ab3c479a7 to your computer and use it in GitHub Desktop.
Wumboji maker- WIP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Drawing; | |
namespace wumboji | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Wumboji v1.2 -- Released under MIT License by aozkal, source code at https://gist.github.com/ardaozkal/1bfe45f2c6f2100702dd146ab3c479a7"); | |
// Compile with mcs wumboji.cs /reference:System.Drawing.dll | |
while (true) | |
{ | |
Console.WriteLine("Specify image file name:"); | |
var imageName = Console.ReadLine(); | |
if (!File.Exists(imageName)) | |
{ | |
Console.WriteLine("File does not exist or cannot be found. Try copying it to the same directory as the executable and try again."); | |
} | |
else | |
{ | |
var selectedImage = Bitmap.FromFile(imageName); | |
var imageHeight = selectedImage.Height; | |
var imageWidth = selectedImage.Width; | |
var projectName = Path.GetFileNameWithoutExtension(imageName); | |
var imageFormat = Path.GetExtension(imageName); | |
Console.WriteLine("How many vertical lines should be made? [default: 5]"); | |
var verticalLines = Console.ReadLine(); | |
int intVerticalLines; | |
int verticalBoxSize; | |
if (verticalLines.Trim() == "") | |
{ | |
intVerticalLines = 5; | |
} | |
else if (!int.TryParse(verticalLines, out intVerticalLines)) | |
{ | |
intVerticalLines = 5; | |
Console.WriteLine("Meh I couldn't understand that and am too lazy to do stuff so going with 5. Restart the app and properly write the number if that's not fine for you."); | |
} | |
verticalBoxSize = imageHeight / intVerticalLines; | |
Console.WriteLine("How many horizontal lines should be made? [default: {0}]", intVerticalLines); | |
var horizontalLines = Console.ReadLine(); | |
int intHorizontalLines; | |
int horizontalBoxSize; | |
if (horizontalLines.Trim() == "") | |
{ | |
intHorizontalLines = intVerticalLines; | |
} | |
else if (!int.TryParse(horizontalLines, out intHorizontalLines)) | |
{ | |
intHorizontalLines = intVerticalLines; | |
Console.WriteLine("Meh I couldn't understand that and am too lazy to do stuff so going with {0}. Restart the app and properly write the number if that's not fine for you.", intVerticalLines); | |
} | |
horizontalBoxSize = imageWidth / intHorizontalLines; | |
if (!Directory.Exists("ImageCropper")) | |
{ | |
Directory.CreateDirectory("ImageCropper"); // It shouldn't throw anything if it does exist but whatever. | |
} | |
var imageCount = 0; | |
var discordString = ""; | |
for (int v = 0; v < intVerticalLines; v++) | |
{ | |
int VertSomething = v * verticalBoxSize; | |
for (int h = 0; h < intHorizontalLines; h++) | |
{ | |
int HoriSomething = h * horizontalBoxSize; | |
imageCount++; | |
var cutRect = new Rectangle(HoriSomething, VertSomething, horizontalBoxSize, verticalBoxSize); | |
var fileName = "ImageCropper/" + projectName + imageCount + imageFormat; // ImageCropper/LeMemeXd1.png etc | |
discordString += string.Format(":{0}{1}:", projectName, imageCount); | |
CropImage(selectedImage,cutRect).Save(fileName); | |
} | |
discordString += Environment.NewLine; | |
} | |
var discordFileName = "ImageCropper/" + projectName + "discordstring.txt"; | |
File.WriteAllText(discordFileName, discordString); | |
Console.WriteLine("Done! Check the ImageCropper folder to get your images."); | |
Console.WriteLine(); | |
Console.Write("If you want to exist press Enter, press anything else to make another image. "); // typo intended | |
var IWantToDie = Console.ReadKey().Key; | |
if (IWantToDie == ConsoleKey.Enter) | |
{ | |
break; | |
} | |
else if (IWantToDie == ConsoleKey.Escape) | |
{ | |
Console.ForegroundColor = ConsoleColor.Red; | |
Console.WriteLine(); | |
Console.WriteLine(); | |
var edgyText = "There is no escape from this hell."; | |
var edgeArray = edgyText.Split(' '); | |
foreach (var edgyPortion in edgeArray) | |
{ | |
Console.WriteLine(edgyPortion.ToUpper()); | |
} | |
Console.ResetColor(); | |
} | |
} | |
} | |
} | |
public static Bitmap CropImage(Image source, Rectangle section) | |
{ | |
Bitmap bmp = new Bitmap(section.Width, section.Height); | |
Graphics g = Graphics.FromImage(bmp); | |
g.DrawImage(source, 0, 0, section, GraphicsUnit.Pixel); | |
return bmp; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment