mirror of
https://github.com/Palakis/obs-websocket.git
synced 2024-08-30 18:12:16 +00:00
Merge pull request #484 from Palakis/add-screenshot-params
Requests: Add new parameters to TakeSourceScreenshot
This commit is contained in:
@ -1455,6 +1455,8 @@ RpcResponse WSRequestHandler::SetSourceFilterVisibility(const RpcRequest& reques
|
|||||||
* @param {String} `sourceName` Source name. Note that, since scenes are also sources, you can also provide a scene name.
|
* @param {String} `sourceName` Source name. Note that, since scenes are also sources, you can also provide a scene name.
|
||||||
* @param {String (optional)} `embedPictureFormat` Format of the Data URI encoded picture. Can be "png", "jpg", "jpeg" or "bmp" (or any other value supported by Qt's Image module)
|
* @param {String (optional)} `embedPictureFormat` Format of the Data URI encoded picture. Can be "png", "jpg", "jpeg" or "bmp" (or any other value supported by Qt's Image module)
|
||||||
* @param {String (optional)} `saveToFilePath` Full file path (file extension included) where the captured image is to be saved. Can be in a format different from `pictureFormat`. Can be a relative path.
|
* @param {String (optional)} `saveToFilePath` Full file path (file extension included) where the captured image is to be saved. Can be in a format different from `pictureFormat`. Can be a relative path.
|
||||||
|
* @param {String (optional)} `fileFormat` Format to save the image file as (one of the values provided in the `supported-image-export-formats` response field of `GetVersion`). If not specified, tries to guess based on file extension.
|
||||||
|
* @param {int (optional)} `compressionQuality` Compression ratio between -1 and 100 to write the image with. -1 is automatic, 1 is smallest file/most compression, 100 is largest file/least compression. Varies with image type.
|
||||||
* @param {int (optional)} `width` Screenshot width. Defaults to the source's base width.
|
* @param {int (optional)} `width` Screenshot width. Defaults to the source's base width.
|
||||||
* @param {int (optional)} `height` Screenshot height. Defaults to the source's base height.
|
* @param {int (optional)} `height` Screenshot height. Defaults to the source's base height.
|
||||||
*
|
*
|
||||||
@ -1557,20 +1559,30 @@ RpcResponse WSRequestHandler::TakeSourceScreenshot(const RpcRequest& request) {
|
|||||||
|
|
||||||
OBSDataAutoRelease response = obs_data_create();
|
OBSDataAutoRelease response = obs_data_create();
|
||||||
|
|
||||||
|
int compressionQuality {-1};
|
||||||
|
if (request.hasField("compressionQuality")) {
|
||||||
|
compressionQuality = obs_data_get_int(request.parameters(), "compressionQuality");
|
||||||
|
|
||||||
|
if (compressionQuality < -1 || compressionQuality > 100) {
|
||||||
|
QString errorMessage = QString("compression quality out of range: %1").arg(compressionQuality);
|
||||||
|
return request.failed(errorMessage.toUtf8());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (request.hasField("embedPictureFormat")) {
|
if (request.hasField("embedPictureFormat")) {
|
||||||
const char* pictureFormat = obs_data_get_string(request.parameters(), "embedPictureFormat");
|
const char* pictureFormat = obs_data_get_string(request.parameters(), "embedPictureFormat");
|
||||||
|
|
||||||
QByteArrayList supportedFormats = QImageWriter::supportedImageFormats();
|
QByteArrayList supportedFormats = QImageWriter::supportedImageFormats();
|
||||||
if (!supportedFormats.contains(pictureFormat)) {
|
if (!supportedFormats.contains(pictureFormat)) {
|
||||||
QString errorMessage = QString("Unsupported picture format: %1").arg(pictureFormat);
|
QString errorMessage = QString("unsupported picture format: %1").arg(pictureFormat);
|
||||||
return request.failed(errorMessage.toUtf8());
|
return request.failed(errorMessage.toUtf8());
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray encodedImgBytes;
|
QByteArray encodedImgBytes;
|
||||||
QBuffer buffer(&encodedImgBytes);
|
QBuffer buffer(&encodedImgBytes);
|
||||||
buffer.open(QBuffer::WriteOnly);
|
buffer.open(QBuffer::WriteOnly);
|
||||||
if (!sourceImage.save(&buffer, pictureFormat)) {
|
if (!sourceImage.save(&buffer, pictureFormat, compressionQuality)) {
|
||||||
return request.failed("Embed image encoding failed");
|
return request.failed("embed image encoding failed");
|
||||||
}
|
}
|
||||||
buffer.close();
|
buffer.close();
|
||||||
|
|
||||||
@ -1587,7 +1599,18 @@ RpcResponse WSRequestHandler::TakeSourceScreenshot(const RpcRequest& request) {
|
|||||||
QFileInfo filePathInfo(filePathStr);
|
QFileInfo filePathInfo(filePathStr);
|
||||||
QString absoluteFilePath = filePathInfo.absoluteFilePath();
|
QString absoluteFilePath = filePathInfo.absoluteFilePath();
|
||||||
|
|
||||||
if (!sourceImage.save(absoluteFilePath)) {
|
const char* fileFormat = nullptr;
|
||||||
|
if (request.hasField("fileFormat")) {
|
||||||
|
fileFormat = obs_data_get_string(request.parameters(), "fileFormat");
|
||||||
|
QByteArrayList supportedFormats = QImageWriter::supportedImageFormats();
|
||||||
|
|
||||||
|
if (!supportedFormats.contains(fileFormat)) {
|
||||||
|
QString errorMessage = QString("unsupported file format: %1").arg(fileFormat);
|
||||||
|
return request.failed(errorMessage.toUtf8());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!sourceImage.save(absoluteFilePath, fileFormat, compressionQuality)) {
|
||||||
return request.failed("Image save failed");
|
return request.failed("Image save failed");
|
||||||
}
|
}
|
||||||
obs_data_set_string(response, "imageFile", absoluteFilePath.toUtf8());
|
obs_data_set_string(response, "imageFile", absoluteFilePath.toUtf8());
|
||||||
|
Reference in New Issue
Block a user