32 #ifdef USE_IMAGEMAGICK 40 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) {
47 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)
48 : 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)
56 text_background_color = color;
70 image = std::make_shared<Magick::Image>(
71 Magick::Geometry(width,height), Magick::Color(background_color));
74 image->backgroundColor(Magick::Color(
"none"));
80 lines.push_back(Magick::DrawableGravity(Magick::NorthWestGravity));
83 lines.push_back(Magick::DrawableGravity(Magick::NorthGravity));
86 lines.push_back(Magick::DrawableGravity(Magick::NorthEastGravity));
89 lines.push_back(Magick::DrawableGravity(Magick::WestGravity));
92 lines.push_back(Magick::DrawableGravity(Magick::CenterGravity));
95 lines.push_back(Magick::DrawableGravity(Magick::EastGravity));
98 lines.push_back(Magick::DrawableGravity(Magick::SouthWestGravity));
101 lines.push_back(Magick::DrawableGravity(Magick::SouthGravity));
104 lines.push_back(Magick::DrawableGravity(Magick::SouthEastGravity));
109 lines.push_back(Magick::DrawableStrokeColor(Magick::Color(
"none")));
110 lines.push_back(Magick::DrawableStrokeWidth(0.0));
111 lines.push_back(Magick::DrawableFillColor(text_color));
112 lines.push_back(Magick::DrawableFont(font));
113 lines.push_back(Magick::DrawablePointSize(size));
114 lines.push_back(Magick::DrawableText(x_offset, y_offset, text));
116 if (!text_background_color.empty()) {
117 lines.push_back(Magick::DrawableTextUnderColor(Magick::Color(text_background_color)));
171 auto image_frame = std::make_shared<Frame>(
172 requested_frame, image->size().width(), image->size().height(),
176 auto copy_image = std::make_shared<Magick::Image>(*image.get());
177 copy_image->modifyImage();
179 image_frame->AddMagickImage(copy_image);
185 auto image_frame = std::make_shared<Frame>(1, 640, 480,
"#000000", 0, 2);
205 root[
"type"] =
"TextReader";
206 root[
"width"] = width;
207 root[
"height"] = height;
208 root[
"x_offset"] = x_offset;
209 root[
"y_offset"] = y_offset;
213 root[
"text_color"] = text_color;
214 root[
"background_color"] = background_color;
215 root[
"text_background_color"] = text_background_color;
216 root[
"gravity"] = gravity;
230 catch (
const std::exception& e)
233 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
244 if (!root[
"width"].isNull())
245 width = root[
"width"].asInt();
246 if (!root[
"height"].isNull())
247 height = root[
"height"].asInt();
248 if (!root[
"x_offset"].isNull())
249 x_offset = root[
"x_offset"].asInt();
250 if (!root[
"y_offset"].isNull())
251 y_offset = root[
"y_offset"].asInt();
252 if (!root[
"text"].isNull())
253 text = root[
"text"].asString();
254 if (!root[
"font"].isNull())
255 font = root[
"font"].asString();
256 if (!root[
"size"].isNull())
257 size = root[
"size"].asDouble();
258 if (!root[
"text_color"].isNull())
259 text_color = root[
"text_color"].asString();
260 if (!root[
"background_color"].isNull())
261 background_color = root[
"background_color"].asString();
262 if (!root[
"text_background_color"].isNull())
263 text_background_color = root[
"text_background_color"].asString();
264 if (!root[
"gravity"].isNull())
275 #endif //USE_IMAGEMAGICK int num
Numerator for the fraction.
Align clip to the right of its parent (middle aligned)
Align clip to the bottom right of its parent.
int width
The width of the video (in pixesl)
float duration
Length of time (in seconds)
double ToDouble() const
Return this fraction as a double (i.e. 1/2 = 0.5)
const Json::Value stringToJson(const std::string value)
void SetTextBackgroundColor(std::string color)
bool has_video
Determines if this file has a video stream.
void Open() override
Open Reader - which is called by the constructor automatically.
int64_t file_size
Size of file (in bytes)
Align clip to the top right of its parent.
Align clip to the bottom left of its parent.
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
Header file for all Exception classes.
bool has_audio
Determines if this file has an audio stream.
virtual Json::Value JsonValue() const =0
Generate Json::Value for this object.
int64_t video_length
The number of frames in the video stream.
int height
The height of the video (in pixels)
Align clip to the bottom center of its parent.
Align clip to the top left of its parent.
openshot::Fraction video_timebase
The video timebase determines how long each frame stays on the screen.
Header file for TextReader class.
This class represents a fraction.
Align clip to the left of its parent (middle aligned)
TextReader()
Default constructor (blank text)
virtual void SetJsonValue(const Json::Value root)=0
Load Json::Value into this object.
void Close() override
Close Reader.
openshot::ReaderInfo info
Information about the current media file.
Align clip to the center of its parent (middle aligned)
std::string vcodec
The name of the video codec used to encode / decode the video stream.
This namespace is the default namespace for all code in the openshot library.
Json::Value JsonValue() const override
Generate Json::Value for this object.
Exception for invalid JSON.
openshot::Fraction display_ratio
The ratio of width to height of the video stream (i.e. 640x480 has a ratio of 4/3) ...
std::shared_ptr< openshot::Frame > GetFrame(int64_t requested_frame) override
openshot::Fraction pixel_ratio
The pixel ratio of the video stream as a fraction (i.e. some pixels are not square) ...
void SetJson(const std::string value) override
Load JSON string into this object.
Align clip to the top center of its parent.
int den
Denominator for the fraction.
openshot::Fraction fps
Frames per second, as a fraction (i.e. 24/1 = 24 fps)
GravityType
This enumeration determines how clips are aligned to their parent container.
std::string Json() const override
Generate JSON string of this object.