View Full Version : Creating 3-color PNG
tacman1123
2nd June 2008, 17:39
I'm trying to create a 3-color PNG file (for a DVD menu), is this possible with ImageWriter()? Maybe with the ImageMagick extension?
f=Blank.SubtitleEx("intro", x=300, y=120, textcolor=$0000FF00).trim(0,1)
f=f.SubtitleEx("meet", x=300, y=200, textcolor=$0000FF00).trim(0,1)
f1=f
f1=ImageWriter(f1.ConvertToRGB(),"c:\hold\daver\normal",0, 3, type="png",info=true)
DVD Menu Subtitles require 3-color png (at least using DVDAuthor), but I'm not sure how to automatically create them.
Thx,
Tac
tacman1123
2nd June 2008, 19:15
To be more specific, this is what I'm trying to do:
Create your subtitle images. There are in fact 3 of them: the basic subtitles image ... It is recommended to save these images in PNG format. ...
There are a number of important points to note:
* There may be no more than 4 colours in any image.
* Therefore you should disable all antialiasing (text tool and selections).
* Saving in indexed mode with a colour table of size 3 helps to force this (transparent is a colour in subtitle menus but not in gimp colour tables). RGB mode images are accepted but they won't check that you haven't got too many colours.
So I'm trying to follow these requirements, no idea how to go about restricting the color palette to just 4.
To be more specific, this is what I'm trying to do:
So I'm trying to follow these requirements, no idea how to go about restricting the color palette to just 4.
why do you want to use avisynth for this???
simply create your image with the gimp... and, if you want, import it in avisynth with imagereader
Wilbert
2nd June 2008, 20:26
I'm trying to create a 3-color PNG file (for a DVD menu), is this possible with ImageWriter()? Maybe with the ImageMagick extension?
I might be able to add this in the ImageMagick extension. Does the color palette need to be the same for every image?
tacman1123
2nd June 2008, 20:52
I don't know, tin2tin might know, I think he did some work with this in DVD Slideshow GUI, I'll PM him and ask.
tacman1123
2nd June 2008, 21:15
Since you're an ImageMagick expert, if you could post how to create, using the command line version, a 3-color png file with a text caption and control the color and location of that caption, I can test it with DVD Author. Boatloads of IM CLI options, overwhelming...
Thx,
Tac
Wilbert
3rd June 2008, 23:18
There are several options (i guess you need to use 4 colors with black included):
1) uses a (changing) palette of 3 colors:
convert subs.png -type Palette +dither -colors 3 output.png
2) uses a fixed palette of 3 colors with a colortable:
convert subs.png -type Palette +dither -map colortable.gif output.png
Here a color table is used, which is just a picture with three colors. I guess you could stack three horizontal bars with different colors and save it as colortable.gif (in AviSynth).
As a note to myself, i need to use MapImages (http://www.imagemagick.org/api/quantize.php) for the latter.
Note that i didn't test these command lines yet.
references:
http://www.imagemagick.org/script/command-line-options.php
http://www.imagemagick.org/Usage/quantize/
tacman1123
4th June 2008, 03:32
Thanks, getting closer. I no longer get the error message when using DVDAuthor, but instead of getting the menu titles, I get a black image (the background). I think this is because I don't have an alpha color set, although I'm not even 100% sure I know what that mean (a transparent color?), and I definitely don't know if it's set/how to set it. Is it possible with convert?
For some reason, creating the png files didn't work from within avisynth, either using ImageWriter or ImmaWrite, but creating jpgs work, so I did that, and then did the convert using the -colors 3 parameter, as you suggested. Any idea how to get the alpha color? Also, not quite sure what to do with the colormap you mentioned in your example.
Thanks!
Tac
Wilbert
4th June 2008, 11:53
Thanks, getting closer. I no longer get the error message when using DVDAuthor, but instead of getting the menu titles, I get a black image (the background). I think this is because I don't have an alpha color set, although I'm not even 100% sure I know what that mean (a transparent color?), and I definitely don't know if it's set/how to set it. Is it possible with convert?
I think you should create a png with a "white" alpha channel. You can do that in AviSynth using Blankclip and Mask, or with ImageMagick:
convert subs.png -type Palette +dither -colors 3 -matte -transparent "#FFFFFF" output.png
where subs.png is without alpha channel. (I'm not sure about the order of the arguments though.)
But when reading the dvd authoring guides on this site, they don't mention picture subtitles with an alpha channel. They set the transparency of the colors in the authoring program itself. Perhaps you are doing this wrong?
Sorry, i never worked with picture subtitles. So i'm not sure how to do stuff like this.
For some reason, creating the png files didn't work from within avisynth, either using ImageWriter or ImmaWrite
What goes wrong? Do you get an error message?
Btw, i don't think that jpg supports alpha or a palette.
tacman1123
4th June 2008, 20:56
Borax, the author of DVDAuthor, pointed me to this thread that shows how to use Avisynth to create the mysterious 3-color subtitle images:
http://forum.gleitz.info/showpost.php?p=270087&postcount=39
Unfortunately, it's from 2003 (and in German), and all the VSFilter.dll's I've downloaded have caused "unhandled exception" errors when running the script as posted, so I'm wondering if anyone here can help with the TextSub plugin.
I still like the idea of doing it in ImageMagick better, but that's mostly because it's very understandable, where the subtitles files are yet another format to learn.
Tac
Wilbert
4th June 2008, 22:05
Borax, the author of DVDAuthor, pointed me to this thread that shows how to use Avisynth to create the mysterious 3-color subtitle images:
This works fine for me. Copy the latest VSFilter: http://forum.doom9.org/showthread.php?p=1143082#post1143082 to your plugin folder. Remove the LoadPlugin line from your script. Does that work?
Btw, it is saved to an ordinary 24-bit bmp image sequence (without alpha channel). Nothing special about that.
I still like the idea of doing it in ImageMagick better, but that's mostly because it's very understandable, where the subtitles files are yet another format to learn.
Why don't you try Aegisub for creating the subtitles?
tacman1123
4th June 2008, 22:40
Argh, I got burned on this before, and now again. When I cut and paste from the forum in Firefox, the file gets saved with unix line endings, rather than DOS (CR/LF). When I resaved the .ass file with the proper endings, everything worked. Well, I don't know about everything, but I'm now at least seeing what I'm supposed to see!
Thanks, will report more later, hopefully can close out this thread with a DVD menuing solution in Avisynth.
Tac
tacman1123
4th June 2008, 23:16
Question: when you ran this, where did the bmp files get created? Unless I give it the full path, I can't find them, even though if info=true is on it shows them being created. I think this is the problem I was seeing before with ImageMagick as well, not finding the created files.
A feature request: IF the output file is exactly one frame AND there's already an extension on it that matches the type, could you just write out that file to that name, rather than using that string as a template? E.g. f.ImmaWrite("menu.jpg", 0, 1, type="jpg" ) shouldn't write the file to menu.jpg000001.jpg, the user obviously would prefer the file to be written to menu.jpg.
At least, I would!
Thx,
Tac
tacman1123
5th June 2008, 12:17
why do you want to use avisynth for this???
simply create your image with the gimp... and, if you want, import it in avisynth with imagereader
I want to be able to programmatically create DVD's with menus from a library of videos. So I need to work around anything that fires up a User Interface and requires dragging and dropping and any human interaction.
Wilbert
5th June 2008, 18:03
Question: when you ran this, where did the bmp files get created? Unless I give it the full path, I can't find them, even though if info=true is on it shows them being created.
Please post a script which has this problem. If i use ImageWriter or ImmaWrite it saves them in the same folder as my script (unless you specify the full path).
A feature request: IF the output file is exactly one frame AND there's already an extension on it that matches the type, could you just write out that file to that name, rather than using that string as a template? E.g. f.ImmaWrite("menu.jpg", 0, 1, type="jpg" ) shouldn't write the file to menu.jpg000001.jpg, the user obviously would prefer the file to be written to menu.jpg.
I think that you will do it only the first time wrong :) It's either this behaviour or removing the "type" argument entirely.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.