I am trying to to generate and save empty zip with FileSaver.js in Chrome browser.
saveAs(new Blob([], {type: "application/zip"}), "empty.zip");
it asks me to save "empty.zip" on disk.
file is being created fine (0 bytes)
i can drag and drop file in Windows explorer there.
but 7-zip does not open it
what should i pass as Blob content argument instead of empty array [] to get proper zip ?
An empty zip file is not an empty file: it needs an "end of central directory record" listing 0 entry (see 4.3.16 End of central directory record for the reference). Even with that, some tools complain that the zip file is empty. I can't test 7zip right now, it may happens to you.
If you don't want to load a zip library just to generate this empty zip file, you can write the 22 bytes:
var buffer = new Uint8Array([ 80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]).buffer;
var blob = new Blob([buffer], {type: "application/zip"});
Related
I'm trying to use midiutil to create a program that converts text into a midi file. I have thus far been able to do everything successfully, however midiutil does not appear to be functioning correctly. When I execute the code, it appears to complete fine, but no file is written. I've tried copying and pasting the default example from the documentation, and the same problem occurs. The code appears to run correctly, but no file is created. I have also tried manually creating the file first in hopes that it might edit the existing file, but that also doesn't work. For reference, here is the example code from the documentation that is NOT working correctly when I attempt to run it.
from midiutil import MIDIFile
degrees = [60, 62, 64, 65, 67, 69, 71, 72] # MIDI note number
track = 0
channel = 0
time = 0 # In beats
duration = 1 # In beats
tempo = 60 # In BPM
volume = 100 # 0-127, as per the MIDI standard
MyMIDI = MIDIFile(1) # One track, defaults to format 1 (tempo track
# automatically created)
MyMIDI.addTempo(track,time, tempo)
for pitch in degrees:
MyMIDI.addNote(track, channel, pitch, time, duration, volume)
time = time + 1
with open("major-scale.mid", "wb") as output_file:
MyMIDI.writeFile(output_file)
I begin with python v3.10, I use actually PyQt6 for the design of the windows.
I created a QTableWidget in which I put a checkbox with a picture.
Now I would like to create a signal to execute a function when I click on it.
I tried, connect, stateChanged, ... but nothing works.
I write below my code with a picture :
while self.query.next():
# widget checkbox
checkbox_widget = QWidget()
checkbox_widget.setStyleSheet('background-color: transparent;')
w_checkbox = QtWidgets.QCheckBox
layout_cb = QtWidgets.QHBoxLayout(checkbox_widget)
layout_cb.addWidget(w_checkbox())
layout_cb.setAlignment(Qt.AlignmentFlag.AlignCenter)
layout_cb.setContentsMargins(0, 0, 0, 0)
checkbox_widget.setLayout(layout_cb)
tablerow = self.table_EP.rowCount()
self.table_EP.insertRow(tablerow)
self.table_EP.setItem(tablerow, 0, QtWidgets.QTableWidgetItem((self.query.value('col1'))))
self.table_EP.setItem(tablerow, 1, QtWidgets.QTableWidgetItem((self.query.value('col2'))))
self.table_EP.setItem(tablerow, 2, QtWidgets.QTableWidgetItem((self.query.value('col3'))))
self.table_EP.setItem(tablerow, 3, QtWidgets.QTableWidgetItem((str(self.query.value('col4')))))
self.table_EP.setItem(tablerow, 4, QtWidgets.QTableWidgetItem((str(self.query.value('col5')))))
self.table_EP.setItem(tablerow, 5, QtWidgets.QTableWidgetItem((str(self.query.value('col6')))))
self.table_EP.setItem(tablerow, 6, QtWidgets.QTableWidgetItem((self.query.value('col7'))))
self.table_EP.setItem(tablerow, 7, QtWidgets.QTableWidgetItem((str(self.query.value('col8')))))
self.table_EP.setItem(tablerow, 8, QtWidgets.QTableWidgetItem((str(self.query.value('col9')))))
self.table_EP.setCellWidget(tablerow, 9, w_checkbox())
self.table_EP.setCellWidget(tablerow, 9, checkbox_widget)
w_checkbox.stateChanged.connect(self.clicked_button())
enter image description here
Thank you so much for your help (I'm sorry for my English).
This is some weird code.
Ultimately you need to call .stateChanged.connect(self.clicked_button()) on the instance of QtWidgets.QCheckBox.
You create an instance of the class QtWidgets.QCheckBox with this line: layout_cb.addWidget(w_checkbox()), but you don't assign it to a variable.
You should first assign it to a variable, then refer to it using that variable, like so:
checkbox = QtWidgets.QCheckBox()
layout_cb.addWidget(checkbox)
checkbox.stateChanged.connect(self.clicked_button())
Are you sure you need the brackets after self.clicked_button()? That only makes sense if it returns a function.
I want to have MyTexture.tres to generate the Image, and be able to visualise it both at run time and in the editor.
The goal is to have my own Texture type as a Resource file, that can be used like NoiseTexture, GradientTexture, etc, and to use it in the editor (on a Sprite, as a shader uniform...) and NOT to save any image data in project folder.
tool
extends ImageTexture
export var width := 100
export var height := 100
func _init():
var image := Image.new()
# ...
# Generate the image data array
# ...
create_from_image(image)
Using the tool keyword, it works but the Image data is automatically saved into MyTexture.tres, so it break the best advantage that is to save a lot of space.
I assign a script to the .tres file trying inheriting both ImageTexture and ProxyTexture, but the result is the same once I call create_from_image() it saves it to the file.
[sub_resource type="Image" id=3]
data = {
"data": PoolByteArray( 127, 119, 254, 131, 131, 119, 25, ... ) <-----
"format": "RGBA8",
"height": 512,
"mipmaps": false,
"width": 512
}
May be I will try inheriting ViewportTexture but even if it works it seem wrong, that require accessing the SceneTree to instanciate the Viewport (from a Resource script), may be is there a clean way ?
I am trying to modify existing metadata within python 3. More specifically I have GPS coordinates and altitude in a my metadata, and I need to modify it.
I'm using piexif mudule, and I ancounter two problems.
First, I managed to change Altitude, using
exif_dict['GPS'][piexif.GPSIFD.GPSAltitude] = (140, 1)
and it works.
But I can't understand how to change Latitude and Longtitude? as they consist of three fields, like ((53, 1), (291191, 10000), (0, 1)).
The second problem occurs when I try to save tiff file with modified metadata. If I save it as TIFF file:
img.save(fname_2, 'tiff', exif=exif_bytes),
the fname_2 file is created, but it's metadata isn't changed. If Isave as JPEG -
img.save(fname_2, 'jpeg', exif=exif_bytes)
- metadata changes, but the file is compressed from 289 MB to 15 MB, that makes it impossible to use it for my purposes.
Has anyone managed to do this? It sounds like it would be very simple, but I can't seem to work it out.
import piexif
from PIL import Image
Image.MAX_IMAGE_PIXELS = 1000000000
fname_1='D:\EZG\Codding\photo\iiq/eee.tif'
fname_2='D:\EZG\Codding\photo\iiq/eee_change.tif'
img = Image.open(fname_1)
exif_dict = piexif.load(fname_1)
latitide = exif_dict['GPS'][piexif.GPSIFD.GPSLatitude]
longtitude = exif_dict['GPS'][piexif.GPSIFD.GPSLongitude]
altitude = exif_dict['GPS'][piexif.GPSIFD.GPSAltitude]
print(latitide)
print(longtitude)
print(altitude)
exif_dict['GPS'][piexif.GPSIFD.GPSAltitude] = (140, 1)
exif_bytes = piexif.dump(exif_dict)
img.save(fname_2, 'tiff', exif=exif_bytes)
the fname_2 file is created, but it's metadata isn't changed
Based on other questions and answers on SO it seems that the values are encoded as fractions:
((53, 1), (291191, 10000), (0, 1))
is 53 degrees 291191/10000 = 29.1191 minutes North (0 == N; 1 == S)
You may also want to check this answer, as there is a better package to edit GPS coordinates in photo metadata.
I built a little script that will first montage 8 tiles together, then scale it down and then it has to distort the image.
Everything goes according to plan until the distorting part.
this.distort = function(filename) {
var distortDeferred = Q.defer();
var totalWidth = width * waves * 2,
totalHeight = height * waves * 2;
var params = [
filename,
'-matte',
'-virtual-pixel',
'transparent',
'-distort',
'Perspective "{left},{top} {newLeft},{top} {left},{bottom} {left},{bottom} {right},{bottom} {right},{bottom} {right},{top} {newRight},{top}"'.assign({
left: 0,
top: 0,
newLeft: totalWidth * distortPercentage,
bottom: totalHeight,
right: totalWidth,
newRight: totalWidth - totalWidth * distortPercentage
}),
filename
];
im.convert(params, function() {
console.log(arguments);
});
return distortDeferred.promise;
};
This following function wil give the error:
Error: Command failed: convert: missing an image filename `tmp/5458f2e3d6840bb65ba6100f.png' # error/convert.c/ConvertImageCommand/3184.
Running the exact same operation on the command line, will have the desired output.
Possible mistakes I could have made and that I have tested:
Two image converts, converting the image at the same time
Non existing image
File rights to the image are not set correctly
Missing plugins for ImageMagick
Two image converts, converting the image at the same time
Everything is done with deferreds and promises, so it's not possible that two requests run at the same time, to be sure I set a 2000ms timeout before the distort function was called. Also no help.
Non existing image
Tested this to be sure with a fs.fileExists. Result was as expected.
File rights to the image are not set correctly
To be safe I tried a chmod -R 777 folder on the folder. Result was as expected.
Missing plugins for ImageMagick
After some googling I came across some people that didn't have the appropriate plugins installed and received the same error as me.
Apparently it had something to with either a JPEG library missing or a PNG, see error here.
So after running identify -list format, it was apparent that I have the appropriate libraries installed to complete an operation like this.
Synopsis
I think the error is also probably found in node instead of ImageMagick, because the operation runs from the command line without a problem.