26TextReader::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) {
33TextReader::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)
34: 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)
42 text_background_color = color;
56 image = std::make_shared<Magick::Image>(
57 Magick::Geometry(width,height), Magick::Color(background_color));
60 image->backgroundColor(Magick::Color(
"none"));
66 lines.push_back(Magick::DrawableGravity(Magick::NorthWestGravity));
69 lines.push_back(Magick::DrawableGravity(Magick::NorthGravity));
72 lines.push_back(Magick::DrawableGravity(Magick::NorthEastGravity));
75 lines.push_back(Magick::DrawableGravity(Magick::WestGravity));
78 lines.push_back(Magick::DrawableGravity(Magick::CenterGravity));
81 lines.push_back(Magick::DrawableGravity(Magick::EastGravity));
84 lines.push_back(Magick::DrawableGravity(Magick::SouthWestGravity));
87 lines.push_back(Magick::DrawableGravity(Magick::SouthGravity));
90 lines.push_back(Magick::DrawableGravity(Magick::SouthEastGravity));
95 lines.push_back(Magick::DrawableStrokeColor(Magick::Color(
"none")));
96 lines.push_back(Magick::DrawableStrokeWidth(0.0));
97 lines.push_back(Magick::DrawableFillColor(text_color));
98 lines.push_back(Magick::DrawableFont(font));
99 lines.push_back(Magick::DrawablePointSize(size));
100 lines.push_back(Magick::DrawableText(x_offset, y_offset, text));
102 if (!text_background_color.empty()) {
103 lines.push_back(Magick::DrawableTextUnderColor(Magick::Color(text_background_color)));
157 auto image_frame = std::make_shared<Frame>(
159 image->size().width(), image->size().height(),
163 auto copy_image = std::make_shared<Magick::Image>(*image.get());
164 copy_image->modifyImage();
166 image_frame->AddImage(qimage);
172 auto image_frame = std::make_shared<Frame>(1, 640, 480,
"#000000", 0, 2);
192 root[
"type"] =
"TextReader";
193 root[
"width"] = width;
194 root[
"height"] = height;
195 root[
"x_offset"] = x_offset;
196 root[
"y_offset"] = y_offset;
200 root[
"text_color"] = text_color;
201 root[
"background_color"] = background_color;
202 root[
"text_background_color"] = text_background_color;
203 root[
"gravity"] = gravity;
217 catch (
const std::exception& e)
220 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
231 if (!root[
"width"].isNull())
232 width = root[
"width"].asInt();
233 if (!root[
"height"].isNull())
234 height = root[
"height"].asInt();
235 if (!root[
"x_offset"].isNull())
236 x_offset = root[
"x_offset"].asInt();
237 if (!root[
"y_offset"].isNull())
238 y_offset = root[
"y_offset"].asInt();
239 if (!root[
"text"].isNull())
240 text = root[
"text"].asString();
241 if (!root[
"font"].isNull())
242 font = root[
"font"].asString();
243 if (!root[
"size"].isNull())
244 size = root[
"size"].asDouble();
245 if (!root[
"text_color"].isNull())
246 text_color = root[
"text_color"].asString();
247 if (!root[
"background_color"].isNull())
248 background_color = root[
"background_color"].asString();
249 if (!root[
"text_background_color"].isNull())
250 text_background_color = root[
"text_background_color"].asString();
251 if (!root[
"gravity"].isNull())
Header file for all Exception classes.
Header file for Frame class.
Header file for MagickUtilities (IM6/IM7 compatibility overlay)
Header file for QtUtilities (compatibiity overlay)
Header file for TextReader class.
This class represents a fraction.
int num
Numerator for the fraction.
double ToDouble() const
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.
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.
void Close() override
Close Reader.
std::string Json() const override
Generate JSON string of this object.
TextReader()
Default constructor (blank text)
void Open() override
Open Reader - which is called by the constructor automatically.
void SetTextBackgroundColor(std::string color)
void SetJson(const std::string value) override
Load JSON string into this object.
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
Json::Value JsonValue() const override
Generate Json::Value for this object.
std::shared_ptr< openshot::Frame > GetFrame(int64_t requested_frame) override
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)
std::shared_ptr< QImage > Magick2QImage(std::shared_ptr< Magick::Image >)
Convert Magick::Image to QImage.
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)