SkayaWiki

TiffG4

JeromePetazzoni :: DerniersChangements :: DerniersCommentaires? :: ParametresUtilisateur :: http://www.enix.org/ :: Vous êtes ec2-3-145-166-223.us-east-2.compute.amazonaws.com
Comment générer un fichier au format TIFF G4 (utilisable par TxFax? par exemple) à partir d'une image quelconque :



convert \
-density 300x300 \
-resize 200%x100% \
-sharpen 2 \
-sample '1728x1137>' \
-bordercolor white -border 900 -gravity center -crop 1728x1137+0+0 +repage \
-monochrome \
-sharpen 2 \
-compress group4 \
snapshot[1234].png _fax.tif


Version de guerre :



#!/usr/bin/python
import magic, sys, os
filename = sys.argv[1]

def image2fax(filename):
# we fork to execute vips job, in case of weird vips crash
pid = os.fork()
if pid: os.waitpid(pid, 0)
else:
from vipsCC import VImage, VMask
i = VImage.VImage(filename)
mx,my = 1728,1137
# double horizontal resolution
i = i.zoom(2,1)
# reduce the size of the image (only if needed)
x,y = i.Xsize(), i.Ysize()
xshrink = 1.0*x/mx
yshrink = 1.0*y/my
shrink = max(1.0, xshrink, yshrink)
print xshrink,yshrink,shrink
i = i.shrink(shrink,shrink)
# sharpen the image
i = i.conv(VMask.VIMask("sharpen.mask"))
# add white borders (if needed)
print i.Xsize(), i.Ysize()
i = i.embed(4, (mx-i.Xsize())/2, 0, mx, my)
# write final image
i.write("%s.png"%filename)
sys.exit(0)
assert not os.system("convert -monochrome -compress group4 %s.png %s.tiff"%
(filename,filename))
os.unlink("%s.png"%filename)

False and os.system("convert"
" -resize 200%%x100%% -sharpen 2 -sample '1728x1137>'"
" -bordercolor white -border 900 -gravity center "
" -crop 1728x1137+0+0 +repage "
" -monochrome -sharpen 2 -compress group4"
" %s %s.tiff"%(filename,filename))

m = magic.open(magic.MAGIC_NONE)
m.load()
filetype = m.file(sys.argv[1])
if filetype.startswith("PDF document"):
assert not os.system("pdftoppm -r 200 -gray '%s' '%s'"%(filename,filename))
i=0 ; pages = []
while True:
i += 1
pagefilename = "%s-%d.pgm"%(filename,i)
if not os.path.isfile(pagefilename): break
image2fax(pagefilename)
os.unlink(pagefilename)
pages.append(pagefilename)
assert not os.system("tiffcp %s '%s'"%(
" ".join(["'%s.tiff'"%s for s in pages]), "%s.tiff"%filename))
for page in pages: os.unlink("%s.tiff"%page)
sys.exit(0)
if "image data" in filetype:
image2fax(filename)
sys.exit(0)

raise Exception('Unrecognized file type.')

Il n'y a pas de commentaire sur cette page. [Afficher commentaires/formulaire]