Re: Animated GIF for Control Page

Dave,
Do you have a way I can send you a properly formatted version of the script?
Do you have a way I can send you a properly formatted version of the script?
Software Support and Home Automation Forum
https://forums.indigodomo.com/
#! /usr/bin/env python2.7
# -*- coding: utf-8 -*-
import os
"""
A prototype script for creating a "ticker tape" style animated, horizontally scrolling
long text string, for use on Indigo control pages based on the ImageMagick library.
"""
import subprocess
## Where the animated GIF image will reside. Spaces must be escaped.
work_fldr = "/Library/Application\ Support/Perceptive\ Automation/Indigo\ 7.4/IndigoWebServer/images/controls/static/"
## This variable limits the character width of the "ticker tape" on the Control Page
## The pixel width of the initial .png frame image needs to be sufficient to accomodate
## the specified number of characters at the point size specified in the imageMagick
## setup
DisplayFieldLength = 29
## When finally interrated with Indigo, the line below will point to and Indigo varible.
char_List = " Today: Sunny, with a high near 108. West wind 5 to 10 mph. Tonight: Mostly clear, with a low around 78. West wind around 5 mph becoming calm in the evening. "
## The lines following convert the long string into a list of strings that are
## within the specified width and successively moved one character to the left
list_Of_Chars = []
list_Of_Display_FrameStrings = []
t = char_List
for i in range(len(t)):
t = t[1:] + t[0]
eachDisplayFrameCharList = t[0:DisplayFieldLength]
eachDisplayrameString = "".join(eachDisplayFrameCharList)
## This is the final list of Display Field Strigs
list_Of_Display_FrameStrings.append(eachDisplayrameString)
## Now comes the magic of ImageMagick which converts each display field string into
## a graphic image and combines it with a frame image copied from an initial frame
## template. the new .png frames are then given a sequential number and saved to be
## used by ImageMagic to create the final Gif animation file.
## First part of the output command string.
## The first ImageMagick command specifies the delay time that each animation frame
## waits before the next image is displayed and sets size in pixels of the text image
## within the frame image.
output_cmd = "/opt/local/bin/convert -delay 15 -size 200x27 "
## Next iterate through the items in the list_Of_Display_FrameStrings to create
## sequential frame images based on each sequential display string image.
## those images are saved as enumerated files that will be used to build the animation.
for num in range(1, len(list_Of_Display_FrameStrings) + 1):
## Build each frame image setting the font, font color, t texpoint size, and the
## reference to the text to be added to the frame image.
proc = subprocess.Popen("/opt/local/bin/convert {0}bar.png -font arial -fill Goldenrod -pointsize 70 -gravity center -annotate +10+17 '{1}' "
"{0}bar_frame{2}.png".format(work_fldr, list_Of_Display_FrameStrings[num - 1], num), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
## For debugging, you can look at the shell's return.
#print(proc.communicate())
## Add command to the output command string to save each new frame image.
output_cmd += "-dispose previous -page +0+0 {0}bar_frame{1}.png ".format(work_fldr, num)
## The last part of the output command string
output_cmd += "-loop 0 {0}bar_animation.gif".format(work_fldr)
## Next to last call ImageMagick to actually build the GIF animation usinge the command
## composed in the preceding line
proc1 = subprocess.Popen(output_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
## Finally, emove all of the .png files that were used to create the animaton--since next animated strings may have different file counts
fileCount = len(list_Of_Display_FrameStrings)
for n in range (0,fileCount):
# print((work_fldr+"bar_frame"+str(n)+".png"))
try:
cmd_rm = "rm -rf "+work_fldr+"bar_frame"+str(n)+".png"
os.system(cmd_rm)
#os.remove ("/Library/Application\ Support/Perceptive\ Automation/Indigo\ 7.4/IndigoWebServer/images/controls/static/bar_frame1.png")
except OSError as err:
print("rm -rf "+work_fldr+"bar_frame"+str(n)+".png")
#! /usr/bin/env python2.7
# -*- coding: utf-8 -*-
"""
A prototype script for creating a "ticker tape" style animated, horizontally scrolling
long text string, for use on Indigo control pages based on the ImageMagick library.
"""
import os
import subprocess
try:
import indigo
except ImportError:
pass
# Where the animated GIF image will reside. Spaces must be escaped.
work_folder = "/Library/Application\ Support/Perceptive\ Automation/Indigo\ 7.4/IndigoWebServer/images/controls/static/"
# This variable limits the character width of the "ticker tape" on the Control
# Page The pixel width of the initial .png frame image needs to be sufficient
# to accommodate the specified number of characters at the point size
# specified in the imageMagick setup
display_field_length = 29
# When finally interrated with Indigo, the line below will point to and Indigo variable.
char_list = u" Today: Sunny, with a high near 108. West wind 5 to 10 mph. Tonight: Mostly clear, with a low around 78. West wind around 5 mph becoming calm in the evening."
# The lines following convert the long string into a list of strings that are
# within the specified width and successively moved one character to the left.
list_of_display_frame_strings = []
for i in range(len(char_list)):
char_list = char_list[1:] + char_list[0]
each_display_frame_char_list = char_list[0:display_field_length]
each_display_frame_string = "".join(each_display_frame_char_list)
# This is the final list of Display Field Strings
list_of_display_frame_strings.append(each_display_frame_string)
# Now comes the magic of ImageMagick which converts each display field string
# into a graphic image and combines it with a frame image copied from an
# initial frame template. the new .png frames are then given a sequential
# number and saved to be used by ImageMagic to create the final GIF animation
# file. First part of the output command string.
#
# The first ImageMagick command specifies the delay time that each animation
# frame waits before the next image is displayed and sets size in pixels of the
# text image within the frame image.
output_cmd = "/opt/local/bin/convert -delay 15 -size 200x27 "
# Next iterate through the items in the list_Of_Display_FrameStrings to create
# sequential frame images based on each sequential display string image. Those
# images are saved as enumerated files that will be used to build the
# animation.
for num in range(1, len(list_of_display_frame_strings) + 1):
# Build each frame image setting the font, font color, text point size,
# and the reference to the text to be added to the frame image.
proc = subprocess.Popen("/opt/local/bin/convert {0}bar.png -font arial -fill Goldenrod -pointsize 70 -gravity center -annotate +10+17 '{1}' {0}bar_frame{2}.png".format(
work_folder, list_of_display_frame_strings[num - 1], num), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
# For debugging, you can look at the shell's return.
# indigo.server.log(proc.communicate())
# Add command to the output command string to save each new frame image.
output_cmd += "-dispose previous -page +0+0 {0}bar_frame{1}.png ".format(work_folder, num)
# The last part of the output command string
output_cmd += "-loop 0 {0}bar_animation.gif".format(work_folder)
# Next to last call ImageMagick to actually build the GIF animation using the
# command composed in the preceding line.
proc1 = subprocess.Popen(output_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
# Finally, remove all of the .png files that were used to create the animation--since next animated strings may have different file counts.
file_count = len(list_of_display_frame_strings)
for n in range(0, file_count):
try:
indigo.server.log(u"{0}bar_frame{1}.png".format(work_folder, n))
cmd_rm = "rm -rf {0}bar_frame{1}.png".format(work_folder, n)
os.system(cmd_rm)
except OSError as err:
indigo.server.log(u"rm -rf {0}bar_frame{1}.png".format(work_folder, n))
mgolden50 wrote:Thanks Dave,
The only help I think I need is how to make a call to the following CLI command with the correct form of reference to the list of png frames in work_fldr created by your code.
apngasm -o outfile.png frame1.png frame2.png frame3.png... through frame.png
I imagine its something equivalent to the popen mechanism you used in your code. but I just don't get the syntax yet.
Anyone else have an idea how to do this.
Thanks,
Mike
subprocess.popen(["apngasm", "-o", "outfile.png", "frame1.png", "frame2.png", "frame3.png", "frame.png"])
subprocess.popen("apngasm -o outfile.png frame1.png frame2.png frame3.png frame.png", shell=True)