55.gif

Search (advanced search)
Use this Search form before posting, asking or make a new thread.
Tips: Use Quotation mark to search words (eg. "How To Make Money Online")

06-14-2016, 01:55 AM
Post: #1
[REQ] Image Quote Generator
Hello :)

Does anyone know/have a script that grabs images from a folder and quotes from a txt file and generate a image with a quote randomly?

i fond a great example of what I'm looking for -> http://inspirobot.me/
It's something like that but with the option to upload multiple quotes
(i need the quotes in a different language)
09-10-2016, 01:24 AM
Post: #2
RE: [REQ] Image Quote Generator
Well, if you can compile some C# code you can use this, but I can't afford to spend time on it.

You need to install the .NET version of ImageMagick: Magick.NET-Q16-AnyCPU

You can alter the directory structure if you wish - currently it is

C:\quotes\in.txt - a file of quotes one per line format: Quote|Author e.g.
When there is no peril in the fight, there is no glory in the triumph.|A. Alvarez
c:\quotes\imagein\*.jpg - the images
c:\quotes\fonts\*.ttf - font files

Output directories (create them)
c:\quotes\imageout <<images
c:\quotes\transout <<transparent - useful for overlaying on videos - you can remove that part if you don't want it.

Lastly a minimal front end - a form with 3 textboxes (textBox1 textBox2 and textBox3) and a go button (btnGo)

Magic Button :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using ImageMagick;

namespace Magick_Mantra
{
public partial class Form1 : Form

{
List<string> quotes = new List<string>();
int curr = 0;
public Form1()
{
InitializeComponent();
using (StreamReader r = new StreamReader("c:\\quotes\\in.txt"))
{
string line = r.ReadLine();
while (((line != null)))
{
quotes.Add(line);
line = r.ReadLine();
}
}


}

private void btnGo_Click(object sender, EventArgs e)
{
foreach (string line in quotes)
{
curr += 1;
string[] parts = line.Split('|');
string quote = parts[0];
string author = parts[1];
textBox1.Text = curr.ToString("00000");
textBox2.Text = quote;
textBox3.Text = author;
textBox1.Refresh();
textBox2.Refresh();
textBox3.Refresh();
make_pic(quote, author);
make_transp(quote, author);
}
Environment.Exit(0);

}
private void make_pic(string quote, string author)
{


var rand = new Random();
var files = Directory.GetFiles("c:\\quotes\\imagein", "*.jpg");
string infile = files[rand.Next(files.Length)];
var rand2 = new Random();
var ffiles = Directory.GetFiles("c:\\quotes\\fonts", "*.ttf");
string ffile = ffiles[rand.Next(ffiles.Length)];
using (MagickImage image = new MagickImage(infile))
{
int ih = image.Height;
int iw = image.Width;
int w1 = (int)(iw * 0.9); //box width
int w2 = (int)(iw * 0.05); //box x coord
int h1 = (int)(ih * 0.8); //box1 height
int h2 = (int)(ih * 0.08); //box2 height
int h3 = (int)(ih * 0.05); //box1 y coord
int h4 = (int)(ih * 0.85); //box2 y coord
int s2 = (int)(iw / 400); //box1 stroke
int s3 = (int)(iw / 600); //box2 stroke
int s4 = (int)(iw / 1000); //logo stroke
int l1 = (int)(iw * 0.20); //logo width
int l2 = (int)(ih * 0.06); //logo height
int l3 = (int)(iw * 0.75); //logo x coord
int l4 = (int)(ih * 0.92); //logo ycoord

using (MagickImage image2 = new MagickImage(new MagickColor("transparent"), w1, h1))
{
using (MagickImage image3 = new MagickImage(new MagickColor("transparent"), w1, h2))
{
using (MagickImage image4 = new MagickImage(new MagickColor("transparent"), l1, l2))
{
var random = new Random();
var color1 = String.Format("#{0:X6}", random.Next(0x1000000));
var color2 = String.Format("#{0:X6}", random.Next(0x1000000));
image2.Settings.FillColor = new MagickColor(color1);
image2.Settings.BorderColor = new MagickColor("#0000ff");
image2.Settings.StrokeColor = new MagickColor("#000000");
image2.Settings.StrokeWidth = s2;
image2.Settings.Font = ffile ;
image2.Settings.FontWeight = FontWeight.Bold;
image2.Settings.TextGravity = Gravity.Center;
image2.Read("caption:" + quote);
image.Composite(image2, w2, h3, CompositeOperator.Over);

image3.Settings.FillColor = new MagickColor(color2);
image3.Settings.FontFamily = "Arial";
image3.Settings.TextGravity = Gravity.Center;
image3.Settings.FontWeight = FontWeight.Bold;
image3.Settings.StrokeColor = new MagickColor("#000000");
image3.Settings.StrokeWidth = s3;
image3.Read("caption:" + author);
image.Composite(image3, w2, h4, CompositeOperator.Over);

image4.Settings.FillColor = new MagickColor("#ff0000");
image4.Settings.FontFamily = "Arial";
image4.Settings.TextGravity = Gravity.Center;
image4.Settings.FontWeight = FontWeight.Bold;
image4.Settings.StrokeColor = new MagickColor("#000000");
image4.Settings.StrokeWidth = s4;
image4.Read("caption:Myvideos.xyz");
image.Composite(image4, l3, l4, CompositeOperator.Over);


string filename = "out-" + curr.ToString("00000") + ".jpg";
image.Write("c:\\quotes\\imageout\\" + filename);
}
}
}
}

}
private void make_transp(string quote, string author)
{
using (MagickImage image = new MagickImage(new MagickColor("transparent"), 1280, 720))
{
int ih = image.Height;
int iw = image.Width;
int w1 = (int)(iw * 0.9); //box width
int w2 = (int)(iw * 0.05); //box x coord
int h1 = (int)(ih * 0.8); //box1 height
int h2 = (int)(ih * 0.08); //box2 height
int h3 = (int)(ih * 0.05); //box1 y coord
int h4 = (int)(ih * 0.85); //box2 y coord
int s2 = (int)(iw / 400); //box1 stroke
int s3 = (int)(iw / 600); //box2 stroke
using (MagickImage image2 = new MagickImage(new MagickColor("transparent"), w1, h1))
{
using (MagickImage image3 = new MagickImage(new MagickColor("transparent"), w1, h2))
{
var random = new Random();
var color1 = String.Format("#{0:X6}", random.Next(0x1000000));
var color2 = String.Format("#{0:X6}", random.Next(0x1000000));
image2.Settings.FillColor = new MagickColor(color1);
image2.Settings.BorderColor = new MagickColor("#0000ff");

image2.Settings.StrokeColor = new MagickColor("#000000");
image2.Settings.StrokeWidth = s2;
image2.Settings.FontFamily = "Arial";
image2.Settings.FontWeight = FontWeight.Bold;
image2.Settings.TextGravity = Gravity.Center;
image2.Read("caption:"+quote);
image.Composite(image2, w2, h3, CompositeOperator.Over);

image3.Settings.FillColor = new MagickColor(color2);
image3.Settings.FontFamily = "Arial";
image3.Settings.TextGravity = Gravity.Center;
image3.Settings.FontWeight = FontWeight.Bold;
image3.Settings.StrokeColor = new MagickColor("#000000");
image3.Settings.StrokeWidth = s3;
image3.Read("caption:"+author);
image.Composite(image3, w2, h4, CompositeOperator.Over);




string filename = "out-" + curr.ToString("00000") + ".png";
image.Write("c:\\quotes\\transout\\" + filename);
}
}
}
}
}
}

[Image: UygPxHy.jpg]
[Image: xrATYmh.jpg]




8.gif