I have a few black and white djvu files that I would like to add a few different background images to at random. This is to make it seem more book like and I think looks better.
Using the command line I can extract each image and then write some code to add the background however this bloats the file a lot because of duplication. I would like to add the background to the file once and then include it using the INCL chunk for the other pages. However it is very confusing how to do this through the DjvuLibre command set.
The current djvu file also has a text layer that I would like to extract and then reapply.
I wrote some code to automate the steps here.
Which are listed below:
In order to successfully add a background image to a foreground image, I have to follow these steps (using a DOS Cmd window):
1- extract the bitomal RLE image from the Djvu File
ddjvu -format=rle -v myfile.djvu temp.rle
2- extract (or create) the background image. Be sure that the size of this image is equal or greater than the foreground image in order to have, after a reduction a integer:
e.g. I have a 2592 x 3508 300dpi foreground image, and I want a background image of 100dpi. So I create a 2592] x 3510 100dpi image (I added 2 pixels to the height in order to have 2594 modulo 3=0).
After a 1/3 resampling, I have a 864 x 1170 image.
3- (do something with this background image) and save it as myfile.ppm (24 bits per pixel)
4- join into an unique file the 2 images:
copy /b myfile.rle + myfile.ppm myfile.mix (using a brave old DOS command)
5- encode the new page into a DjVu file:
csepdjvu -vv -d 300 myfile.mix myNewFile.DjVu
Bingo: It works!!!
Related
I started using the ionicons_2-0-1_ios-pause-outline and
http://fa2png.io/r/ionicons/
to convert these to the correct size.
However when I try the iOS iPhone 7 simulator I get this message:
Warning: Input PNG does not have an 8 bit input depth. Please convert
your PNG to 8-bit for optimal performance on iPhone OS
How can I convert icons to png with the correct depth?
Your images are not in 8-bit, images need to be in 8-bit, not 16-bit.
That goes for the icon as well. and iOS only supports 8-bit images as well.
8-bit means 8-bits per color channel, which is 16.7 million colors.
16 bits per channel give 32,769 colors per channel, which is actually 281 trillion possible colors! 16-bit is only used for photo editing,
images still need to be saved back down to 8-bit for printing.
MakeAppIcon is useful website for generating App icons. and IcoFX is a fantastic tool for creating 8-bit depth icon.
The main difference between an 8 bit image and a 16 bit image is the amount of tones available for a given color. So your image has too many colors in it. Here's a list of some applications that can solve this problem for you. http://myappmag.com/make-windows-icons/ from that list; Number 5 seems to be a good option.
Also this can help you find a color within the 8-bit range.
http://neildowning.com/HEX_to_RGB_color_converter.php
Looks like Xamarin requires 8-bit per color channel
(8-bit for Red, 8-bit for Green, and 8-bit for Blue)
http://forums.gamesalad.com/discussion/comment/61399/#Comment_61399
That is called "true color" which is actually PNG-24 (because 24 = 8*3)
https://en.wikipedia.org/wiki/Color_depth#True_color_.2824-bit.29
So why don't we run a python script to do that for us.
If you are not familiar with python, all you need to do is
Download Python (make sure you add pip to your path during setup)
run pip install pillow in the cmd (Run as Administrator if says Access is denied)
. Pillow is an imaging library for python.
Make a file in the folder with your images, call it convert.py
Put the following in it
def convert_to_24(image_file):
from PIL import Image
try:
im = Image.open(image_file)
except(FileNotFoundError):
print(image_file ,"was not found.")
return
print(image_file,"is in",im.mode,"mode.")
if im.mode != "RGB":
im = im.convert("RGB")
im.save(image_file.split('.')[0]+"_24.png")
return
if __name__ == "__main__":
convert_to_24(input('Enter image file name:'))
Open cmd where the script and the images are and type python convert.py
When it asks for the file name, put the file name including the extension, like filename.png
It will tell you in what mode the image was, and will create another image with a name filename_24.png that has 8-bit color pixels (aka 24bit png).
How can I convert icons to png with the correct depth?
Convert to jpg and back to png. That will also remove the alpha (transparency) channel.
In my rails app, i let the user upload images to use as thumbnails for resources they've made. I do all the image processing with imagemagick's convert command: i convert to jpg, letterbox it to 800x600px and then make some smaller thumbnail versions of that.
This is all working fine. The problem is that some images that have come off my iPhone, for example, have the wrong orientation. My desktop seems to variously deal with this: when i see the tiny thumbnail for the image in the file chooser dialog, it's got the wrong orientation, but if I open it in the image viewing tool, it's got the correct orientation.
Presumably there's some header or metadata or something in the image file which tells the app that it needs to rotate the file? I think that I need to read this in before I do any other processing of the image, so that I can rotate the image (if necessary) before doing all the other stuff.
Can anyone tell me how I can do this, in bash on an Ubuntu server?
thanks, Max
EDIT: a bit of googling suggests that this is to to with EXIF headers...
It's true that you will have to look for orientation value reading Exif metadata of Image. Using imagemagick you can get this value by
identify -format '%[exif:orientation]' <Path to Image>
//or by using
identify -format '%[orientation]' <Path to Image>
Exif Orientation values range from 1 to 8 and maps to orientation as below:
1 = Horizontal (normal)
2 = Mirror horizontal
3 = Rotate 180
4 = Mirror vertical
5 = Mirror horizontal and rotate 270 CW
6 = Rotate 90 CW
7 = Mirror horizontal and rotate 90 CW
8 = Rotate 270 CW
Thus, image would require orientation correction if this metadata tag returns with a non 1 value. If this tag returns with no value it can be assumed to be having normal orientation.
To correct orientation to normal you can use following command
convert -auto-orient <inputImagePath> <outputImagePath>
Try
identify -format "%f %[EXIF:Orientation]" <imagename>
This gives a number from 1 to 8. These numbers are documented here
What is the best way to generate the ".VTT" file and the jpg sprite attached with it for the Tooltip Thumbnails of Jwplayer (http://www.jwplayer.com/blog/building-tooltip-thumbnails-with-encodingcom/- ?
I know how to make an image sprite with php, but i dont know how to make the screenshots of each video with the time in second.. I think there must be a server tool to do all the tasks it but i cant find it.
Thanks
I wrote a script to do this task. Given a video file (MP4 or M4v), generate thumbnail images, compress into a sprite, and generate a VTT file compatible with JWPlayer tooltip thumbnails. All of the image manipulation uses tools from ffmpeg, ImageMagick, and optionally sips and optipng. The WebVTT generation part, I had to write.
You will have to install ffmpeg & imagemagick, at a minimum to use this.
Github code is here: https://github.com/vlanard/videoscripts (under sprites/).
The basic gist is:
Create a bunch of thumbnails, e.g. every 45th second from a video
ffmpeg -i ../archive/myvideofile.mp4 -f image2 -bt 20M -vf fps=1/45 thumbs/myvideofile/tv%03d.png
Resize those thumbnails to be small, e.g. 100pixels wide
sips --resampleWidth 100 thumbs/myvideofile/tv001.png thumbs/myvideofile/tv002.png thumbs/myvideofile/tv003.png
OR if sips not available, use imageMagick utility:
mogrify -geometry 100x thumbs/myvideofile/tv001.png thumbs/myvideofile/tv002.png thumbs/myvideofile/tv003.png
Get the height & width dimensions of one of the thumbnails to use as the basis of our grid coordinates, using ImageMagick utility
identify -format "%g - %f" thumbs/myvideofile/tv001.png
which returns output like :
100x55+0+0 - tv001.png
from which we parse 100 and 55 as our Width & Height, and the general geometry of each thumbnail (W, H, X, Y)
We then generate our single spritemap from the individual thumbnails. We determine the target grid size (e.g. 2x2, 8x8) to suit the number of thumbnails we generated for this video, as well as passing in the sprite geometry, using an ImageMagick utility
montage thumbs/myvideofile/tv*.png -tile 2x2 -geometry 100x55+0+0 thumbs/myvideofile/myvideofile_sprite.png
Optionally we can run an extra compression step here to make the sprite smaller
optipng thumbs/myvideofile/myvideofile_sprite.png
We then generate a VTT file based on the number of thumbnails we created, using
the interval that we used to space out the thumbnails to label each time segment, and
using the known coordinates of each consecutive image within our sprite that maps to
the associated segment.
I've developed a Ruby gem to easily create .VTT file and sprite of thumbnails.
Thanks for inspiring #randalv!
You can take a look at it here:
https://github.com/scaryguy/jwthumbs
Usage
Instantiate your video file:
movie = Jwthumbs::Movie.new("YOUR_VIDEO.mp4")
Jwthumbs::Movie.new accepts second parameter as a options hash. You can configure several stuff at the same time you instantiate your video like this:
movie = Jwthumbs::Movie.new("YOUR_VIDEO.mp4", seconds_between: 60, sprite_name: "my_sprite_name.jpg")
or after you instentiated your video, you can use Jwthumbs::Movie file to configure things:
movie = Jwthumbs::Movie.new("YOUR_VIDEO.mp4")
movie.seconds_between = 60
movie.sprite_name = "my_sprite_name.jpg"
and then to create your thumbnails and .VTT file just run this command.
movie.create_thumbs!
I know this is already a few years old but I had the same problem and found a command line tool which generates sprites pretty fast and since 1.0.6 supports WebVTT creation out of the box. The name is mt and you can check it here.
Quoting from their documentation you can use it like this:
just run mt and provide any video file as args: mt video.avi
Some of the settings can be changed through runtime flags provided
directly to mt for more information just run mt --help
Option 1 :
You can use the encoding.com's API and tell them to export vtt file too
I recommend to read "How can I create time synced thumbnails for use in JW player?" explanation from encoding.com's Knowledge base
Option 2 :
use movie thumbnailer (mtn), this is a command line tools running on UNIX, Windows systems. But you will have to write a custom script to generate the VTT file corresponding
Super fast! Thanks to FFmpeg's libavcodec.
Command line program: canbe used on remote connections to co-location servers, or used in scripts.
Batch mode: recursively search directories for movie files. Run at lower priority (nice 10 on Linux, idle on Windows) by default.
To run at normal priority use -n option.
Thumbnails are group together in one jpeg file and can be saved individually too (-I
option).
Work fine with Unicode filenames in both Linux & Windows
(might need to change the font with -f fontfile).
I'm having trouble viewing a file that is declared to be a TIFF HDR image by Hugin.
Windows Explorer "Properties => Details" states that the bit-depth of the image is 128
Windows Explorer shows it as a white image.
I've tried converting the image to JPEG via ImageMagick, white image.
Picasa Image Viewer says "Invalid image".
I've tried opening it in Photoshop CS5, white image.
These are the stiching options set in Hugin; http://i.imgur.com/vmzA9.png
These is the Images tab in Hugin; http://i.imgur.com/33ySq.png
This is the entire output of Hugin; http://i.imgur.com/smV6O.png
Here is the complete TIFF _hdr file; http://c759972.r72.cf0.rackcdn.com/DSC_3873-DSC_3875_hdr.tif Size: 64 MB
So, is the problem that I'm not viewing it in the correct mode -- or that it really is a white image?
I imported your image using Mathematica. After import, it appears white. That is because the pixel values are not scaled properly: The maximum value is 1070 whereas any value greater than 1 is displayed as white. When rescaling the values to run in the range from 0 to 1, one can see the following:
In[64]:= image = Import["http://c759972.r72.cf0.rackcdn.com/DSC_3873-DSC_3875_hdr.tif"];
In[65]:= ImageType[image]
Out[65]= "Real32"
In[66]:= Max[ImageData[image]]
Out[66]= 1070.
In[67]:= ImageAdjust[image]
Either the image file is indeed corrupted, or the various programs can't read it. Anyway, the image is not white. There seems also to be some mis-alignment between the poses that were used to create the HDR.
I would like to split a large PNG file into A4 pages so they can be printed out easily.
I would like to use a Linux command line script to do this:
shell> split-into-a4-sized-pages some-big.png
I assume you have ImageMagick & pdfposter installed.
A) convert your .png to .pdf (using ImageMagick)
convert input0.png input1.pdf
B) tile your image using pdfposter:
pdfposter -s4 input1.pdf out.pdf
this command enlarges input0 exactly 4 times, print on the default A4
media, and let pdfposter determine the number of pages required.
Try using imagemagick's crop to your desired size.
Say you have a 640x962 image:
and you want to crop it into 4 320x481 images:
Use:
convert pexels-adonyi-gábor-1400172.jpg -crop 240x240+0+0 cropped.jpg
convert pexels-adonyi-gábor-1400172.jpg -crop 320x481+320+0 cropped.jpg
convert pexels-adonyi-gábor-1400172.jpg -crop 320x481+0+481 cropped.jpg
convert pexels-adonyi-gábor-1400172.jpg -crop 320x481+320+481 cropped.jpg
Now you'd have to find out how many pixels fit into an A4 page in your printer, and the dimensions of the image, and it is a very simple script from here.
Photo by Adonyi Gábor from Pexels.
You can use convert of ImageMagick to scale the image; there are probably other tools in ImageMagick to clip the image if you want.
I don't know of any ready-made command line tool to do this. Unless you use it all the time, ImageMagick may take longer to figure out the right combination of commands and options, than to write a quickie program.
An easy way, if you know Python at all, is write a few-line program using PIL (Python Imaging Library). To read an image takes one line. To extract chunks of some width and height at specified location to save as new image files, is also easy. Add a couple for loops to scan rows and columns of A4-sized chunks, and you're done.
If you don't know Python, just about all quick-to-write programming languages have a similar capability. The GD library comes to mind; it has bindings for several languages.
NetPBM's pamdice will do the splitting into multiple pages. You'll have to set the -width and -height options according to the DPI of your desired A4 images.
And you'll also have to convert the input image to netpbm format first with pngtopam:
pngtopam big.png | pamdice -outstem tile -height h -width w
That will leave you will a bunch of files called tile_x_y.ppm
Convert each one of those to PNG with pnmtopng