How do I set the read-only 'frame_duration' property of an image sequence with Python? I try to load in an image sequence as background image with python.
I managed to load it and set the source as sequence, however when i try to set its frame duration according to the number of images in the sequence, I get an error saying that the attribute is read-only.
Can I change this attribute in another way and if not, how can I tell Blender to use it as image sequence?

My code so far:

path="C:\Users\user\Desktop\image0001.png"
img = bpy.data.images.load(path)
img.source = "SEQUENCE"


Prints an error:

img.frame_duration = 50

Traceback (most recent call last):
File "&lt;blender_console&gt;", line 1, in &lt;module&gt;
AttributeError: bpy_struct: attribute "frame_duration" from "Image" is read-
only
frame duration is a calculated value and cannot be set directly.

frame_duration = frame_end - frame_start


In order to change the frame_duration of the sequence you need to change the frame_start and/or frame_end. This makes sense as Blender cannot decide for you which frames you don't want to see (cut from the start or cut from the end, or from the middle, or ....).

# cut the start of the sequence
desired_frame_duration = 50
img.frame_start += img.frame_end - desired_frame_duration

# cut the end of the sequence
desired_frame_duration = 50
img.frame_end = img.frame_start + desired_frame_duration