Thumbnail not working with Cura 5.0 #139
Replies: 5 comments 1 reply
-
https://github.com/mriscoc/Ender3V2S1/wiki/How-to-generate-a-gcode-preview |
Beta Was this translation helpful? Give feedback.
-
Oops I ment I have a DWIN I know for sure my screen was one that could use the thumbnail feature. |
Beta Was this translation helpful? Give feedback.
-
From a comment by Cassius Moura on Facebook: from: PyQt5.QtCore import QByteArray, QIODevice, QBuffer
and
thumbnail_buffer.open(QBuffer.ReadWrite) to: PyQt6.QtCore import QByteArray, QIODevice, QBuffer
and
thumbnail_buffer.open(QBuffer.OpenModeFlag.ReadWrite) Until we release an official plugin you can use this only for Cura v5.0 #--------------------------------------
# Cura v5.0 JPEG Thumbnail creator
# Professional firmware for Ender3v2
# Miguel A. Risco-Castillo
# 2022-05-07
# Contains code from:
# https://github.com/Ultimaker/Cura/blob/master/plugins/PostProcessingPlugin/scripts/CreateThumbnail.py
#--------------------------------------
import base64
from UM.Logger import Logger
from cura.Snapshot import Snapshot
from PyQt6.QtCore import QByteArray, QIODevice, QBuffer
from ..Script import Script
class CreateJPEGThumbnail(Script):
def __init__(self):
super().__init__()
def _createSnapshot(self, width, height):
Logger.log("d", "Creating thumbnail image...")
try:
return Snapshot.snapshot(width, height)
except Exception:
Logger.logException("w", "Failed to create snapshot image")
def _encodeSnapshot(self, snapshot):
Logger.log("d", "Encoding thumbnail image...")
try:
thumbnail_buffer = QBuffer()
thumbnail_buffer.open(QBuffer.OpenModeFlag.ReadWrite)
thumbnail_image = snapshot
thumbnail_image.save(thumbnail_buffer, "JPG")
base64_bytes = base64.b64encode(thumbnail_buffer.data())
base64_message = base64_bytes.decode('ascii')
thumbnail_buffer.close()
return base64_message
except Exception:
Logger.logException("w", "Failed to encode snapshot image")
def _convertSnapshotToGcode(self, encoded_snapshot, width, height, chunk_size=78):
gcode = []
encoded_snapshot_length = len(encoded_snapshot)
gcode.append(";")
gcode.append("; thumbnail begin {}x{} {}".format(
width, height, encoded_snapshot_length))
chunks = ["; {}".format(encoded_snapshot[i:i+chunk_size])
for i in range(0, len(encoded_snapshot), chunk_size)]
gcode.extend(chunks)
gcode.append("; thumbnail end")
gcode.append(";")
gcode.append("")
return gcode
def getSettingDataString(self):
return """{
"name": "Create JPEG Thumbnail",
"key": "CreateJPEGThumbnail",
"metadata": {},
"version": 2,
"settings":
{
"width":
{
"label": "Width",
"description": "Width of the generated thumbnail",
"unit": "px",
"type": "int",
"default_value": 230,
"minimum_value": "0",
"minimum_value_warning": "12",
"maximum_value_warning": "800"
},
"height":
{
"label": "Height",
"description": "Height of the generated thumbnail",
"unit": "px",
"type": "int",
"default_value": 180,
"minimum_value": "0",
"minimum_value_warning": "12",
"maximum_value_warning": "600"
}
}
}"""
def execute(self, data):
width = self.getSettingValueByKey("width")
height = self.getSettingValueByKey("height")
snapshot = self._createSnapshot(width, height)
if snapshot:
encoded_snapshot = self._encodeSnapshot(snapshot)
snapshot_gcode = self._convertSnapshotToGcode(
encoded_snapshot, width, height)
for layer in data:
layer_index = data.index(layer)
lines = data[layer_index].split("\n")
for line in lines:
if line.startswith(";Generated with Cura"):
line_index = lines.index(line)
insert_index = line_index + 1
lines[insert_index:insert_index] = snapshot_gcode
break
final_lines = "\n".join(lines)
data[layer_index] = final_lines
return data |
Beta Was this translation helpful? Give feedback.
-
I had tried this but it didn't work, so I could have dome something wrong somewhere |
Beta Was this translation helpful? Give feedback.
-
I use this code for Cura 5 beta, it creates a PNG. Comment from the manager: |
Beta Was this translation helpful? Give feedback.
-
Just wanted to give a heads up, the code for thumbnails doesn't work with Cura 5.0, I have Tried to edit the default code to make jpg instead of the default png. The main thing I see different is PyQt6.QtCore where urs is PyQt5.QtCore. I have updated my screen firmware I have a 3S1 DACAI, I installed Giadej private firmware. Not saying I didn't do something wrong lol it is possible its on my end
Beta Was this translation helpful? Give feedback.
All reactions