32 #ifdef USE_IMAGEMAGICK
34 #include "../include/TextReader.h"
39 TextReader::TextReader() : width(1024), height(768), x_offset(0), y_offset(0), text(
""), font(
"Arial"), size(10.0), text_color(
"#ffffff"), background_color(
"#000000"), is_open(false), gravity(
GRAVITY_CENTER) {
46 TextReader::TextReader(
int width,
int height,
int x_offset,
int y_offset,
GravityType gravity, std::string text, std::string font,
double size, std::string text_color, std::string background_color)
47 : width(width), height(height), x_offset(x_offset), y_offset(y_offset), text(text), font(font), size(size), text_color(text_color), background_color(background_color), is_open(false), gravity(gravity)
55 text_background_color = color;
69 image = std::shared_ptr<Magick::Image>(
new Magick::Image(Magick::Geometry(width,height), Magick::Color(background_color)));
72 image->backgroundColor(Magick::Color(
"none"));
78 lines.push_back(Magick::DrawableGravity(Magick::NorthWestGravity));
81 lines.push_back(Magick::DrawableGravity(Magick::NorthGravity));
84 lines.push_back(Magick::DrawableGravity(Magick::NorthEastGravity));
87 lines.push_back(Magick::DrawableGravity(Magick::WestGravity));
90 lines.push_back(Magick::DrawableGravity(Magick::CenterGravity));
93 lines.push_back(Magick::DrawableGravity(Magick::EastGravity));
96 lines.push_back(Magick::DrawableGravity(Magick::SouthWestGravity));
99 lines.push_back(Magick::DrawableGravity(Magick::SouthGravity));
102 lines.push_back(Magick::DrawableGravity(Magick::SouthEastGravity));
107 lines.push_back(Magick::DrawableStrokeColor(Magick::Color(
"none")));
108 lines.push_back(Magick::DrawableStrokeWidth(0.0));
109 lines.push_back(Magick::DrawableFillColor(text_color));
110 lines.push_back(Magick::DrawableFont(font));
111 lines.push_back(Magick::DrawablePointSize(size));
112 lines.push_back(Magick::DrawableText(x_offset, y_offset, text));
114 if (!text_background_color.empty()) {
115 lines.push_back(Magick::DrawableTextUnderColor(Magick::Color(text_background_color)));
169 std::shared_ptr<Frame> image_frame(
new Frame(requested_frame, image->size().width(), image->size().height(),
"#000000", 0, 2));
172 std::shared_ptr<Magick::Image> copy_image(
new Magick::Image(*image.get()));
173 copy_image->modifyImage();
175 image_frame->AddMagickImage(copy_image);
181 std::shared_ptr<Frame> image_frame(
new Frame(1, 640, 480,
"#000000", 0, 2));
201 root[
"type"] =
"TextReader";
202 root[
"width"] = width;
203 root[
"height"] = height;
204 root[
"x_offset"] = x_offset;
205 root[
"y_offset"] = y_offset;
209 root[
"text_color"] = text_color;
210 root[
"background_color"] = background_color;
211 root[
"text_background_color"] = text_background_color;
212 root[
"gravity"] = gravity;
226 catch (
const std::exception& e)
229 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
240 if (!root[
"width"].isNull())
241 width = root[
"width"].asInt();
242 if (!root[
"height"].isNull())
243 height = root[
"height"].asInt();
244 if (!root[
"x_offset"].isNull())
245 x_offset = root[
"x_offset"].asInt();
246 if (!root[
"y_offset"].isNull())
247 y_offset = root[
"y_offset"].asInt();
248 if (!root[
"text"].isNull())
249 text = root[
"text"].asString();
250 if (!root[
"font"].isNull())
251 font = root[
"font"].asString();
252 if (!root[
"size"].isNull())
253 size = root[
"size"].asDouble();
254 if (!root[
"text_color"].isNull())
255 text_color = root[
"text_color"].asString();
256 if (!root[
"background_color"].isNull())
257 background_color = root[
"background_color"].asString();
258 if (!root[
"text_background_color"].isNull())
259 text_background_color = root[
"text_background_color"].asString();
260 if (!root[
"gravity"].isNull())
This class represents a fraction.
int num
Numerator for the fraction.
double ToDouble()
Return this fraction as a double (i.e. 1/2 = 0.5)
void Reduce()
Reduce this fraction (i.e. 640/480 = 4/3)
int den
Denominator for the fraction.
This class represents a single frame of video (i.e. image & audio data)
Exception for invalid JSON.
openshot::ReaderInfo info
Information about the current media file.
virtual void SetJsonValue(const Json::Value root)=0
Load Json::Value into this object.
virtual Json::Value JsonValue() const =0
Generate Json::Value for this object.
std::string Json() const override
Get and Set JSON methods.
std::shared_ptr< openshot::Frame > GetFrame(int64_t requested_frame)
TextReader()
Default constructor (blank text)
void SetTextBackgroundColor(std::string color)
void Open()
Open Reader - which is called by the constructor automatically.
Json::Value JsonValue() const override
Generate Json::Value for this object.
void Close()
Close Reader.
void SetJson(const std::string value)
Load JSON string into this object.
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
This namespace is the default namespace for all code in the openshot library.
GravityType
This enumeration determines how clips are aligned to their parent container.
@ GRAVITY_TOP_LEFT
Align clip to the top left of its parent.
@ GRAVITY_LEFT
Align clip to the left of its parent (middle aligned)
@ GRAVITY_TOP_RIGHT
Align clip to the top right of its parent.
@ GRAVITY_RIGHT
Align clip to the right of its parent (middle aligned)
@ GRAVITY_BOTTOM_LEFT
Align clip to the bottom left of its parent.
@ GRAVITY_BOTTOM
Align clip to the bottom center of its parent.
@ GRAVITY_TOP
Align clip to the top center of its parent.
@ GRAVITY_BOTTOM_RIGHT
Align clip to the bottom right of its parent.
@ GRAVITY_CENTER
Align clip to the center of its parent (middle aligned)
const Json::Value stringToJson(const std::string value)
float duration
Length of time (in seconds)
int width
The width of the video (in pixesl)
openshot::Fraction fps
Frames per second, as a fraction (i.e. 24/1 = 24 fps)
openshot::Fraction display_ratio
The ratio of width to height of the video stream (i.e. 640x480 has a ratio of 4/3)
int height
The height of the video (in pixels)
int64_t video_length
The number of frames in the video stream.
std::string vcodec
The name of the video codec used to encode / decode the video stream.
openshot::Fraction pixel_ratio
The pixel ratio of the video stream as a fraction (i.e. some pixels are not square)
bool has_video
Determines if this file has a video stream.
bool has_audio
Determines if this file has an audio stream.
openshot::Fraction video_timebase
The video timebase determines how long each frame stays on the screen.
int64_t file_size
Size of file (in bytes)