FreeImagePy examples

Simple example on how to use FreeImagePy - see into the test subdirectory package for more info.

-------  New method, with the Image class that is more "pythonic"

#File names path
imagePath = 'freeimage.jpg'
imagePathOutPng = 'freeimage.png'
imagePathOutRotate1 = 'freeimageRotate1.png'
imagePathOutRotate2 = 'freeimageRotate2.png'
newMultiPage = "./newMultiFromNewMethod.tif"

#Load the library
import FreeImagePy as FIPY
F = FIPY.Image()
from random import randrange as RR

#Load and save manually. On save you can pass me the type,
I try to understand what image type you want.
# image.png -> file: image, type: png, out: image.png
# image.tif -> file image, type: tiff, out: image.tiff (standard compression)
# image.tiffg4 -> file image, type: tiff G4, out: image.tiff (with g4 compression)
# image.jpeg -> file image, type: jpeg, out: image.jpeg (standard compression)
# image.jpeggo -> file image, type: jpeg, out: image.jpeg (good compression)
# See extToType for more info


#Convert to PIL :
pil = 
pil =F.convertToPil()

del F

#Load, rotate and save
F = FIPY.Image(imagePath)
newI = F.rotate(RR(-360, 360))
del newI, F

F = FIPY.Image(imagePath)
rotated = F.rotate(RR(-360, 360))
del F

#Create a new multi-page image, and use append and delete methods
F = FIPY.Image(),1000), multiBitmap=newMultiPage)
F.appendPage(imagePath) #append from file name
F.deletePage(0) #delete the first page that freeimage NEED to have for work with a multi-page
F.appendPage(bitmap=rotated, insert=0) #and/or insert from bitmap loaded
del rotated

#Convert to single pages

#Create a new image from buffer
f = open(imagePathOutPng, 'rb')
F = FIPY.Image()

-------  Old method
from random import randrange as RR

#Load the library
import FreeImagePy
FIPY = FreeImagePy.freeimage()

#Get some output messages

#File names path
imagePath = 'freeimage.jpg'
imagePathOutPng = 'freeimage.png'
imagePathOutRotate1 = 'freeimageRotate1.png'
imagePathOutRotate2 = 'freeimageRotate2.png'

#Load and save manually
image = FIPY.genericLoader(imagePath)
FIPY.Save(FreeImagePy.FIF_PNG, image, imagePathOutPng)

#Load, rotate and save, but not unload the image, because I want to use it after
image = FIPY.genericLoader(imagePath) # call the generic loader
image = FIPY.RotateClassic(image, RR(-360, 360)) # -> here I cannot pass close = 1
FIPY.Save(FreeImagePy.FIF_PNG, image, imagePathOutRotate1)

#Load, rotate, save and unload the image
image = FIPY.RotateClassic(image, RR(-360, 360), close=1)  # -> here yes ...
FIPY.Save(FreeImagePy.FIF_PNG, image, imagePathOutRotate2)

#Simple method for load and save the image in one step into current directory
FIPY.loadAndSave(imagePathOutRotate1, './out_from_LoadAndSave_', 'bmp')

#Help method for convert the image to a multipage image
FIPY.convertToMultiPage((imagePath, imagePathOutRotate1, imagePathOutRotate2), './out.tif', FreeImagePy.FIF_TIFF)

#and split the image into a lot of singles image...
FIPY.convertToSinglePages('./out.tif', FreeImagePy.FIF_PNG, '.png', 'outputFromSinglesPages')

#Close the library, do it always when you end to use the libray!!!