[DEV] add resizer of the images
This commit is contained in:
parent
cb71051059
commit
eb447c39c5
@ -1,13 +1,15 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
import lutinDebug as debug
|
import lutinDebug as debug
|
||||||
|
import lutinTools as tools
|
||||||
import platform
|
import platform
|
||||||
|
|
||||||
if platform.system() == "Darwin":
|
if platform.system() == "Darwin":
|
||||||
import CoreGraphics
|
import CoreGraphics
|
||||||
else:
|
else:
|
||||||
import image
|
from PIL import Image
|
||||||
|
|
||||||
def resize(srcFile, destFile, x, y):
|
def resize(srcFile, destFile, x, y):
|
||||||
|
extension = destFile[destFile.rfind('.'):]
|
||||||
if platform.system() == "Darwin":
|
if platform.system() == "Darwin":
|
||||||
source_image = CoreGraphics.CGImageImport(CoreGraphics.CGDataProviderCreateWithFilename(srcFile))
|
source_image = CoreGraphics.CGImageImport(CoreGraphics.CGDataProviderCreateWithFilename(srcFile))
|
||||||
source_width = source_image.getWidth()
|
source_width = source_image.getWidth()
|
||||||
@ -18,12 +20,33 @@ def resize(srcFile, destFile, x, y):
|
|||||||
colors = CoreGraphics.CGFloatArray(5)
|
colors = CoreGraphics.CGFloatArray(5)
|
||||||
context = CoreGraphics.CGBitmapContextCreateWithColor(x, y, colors_space, colors)
|
context = CoreGraphics.CGBitmapContextCreateWithColor(x, y, colors_space, colors)
|
||||||
context.setInterpolationQuality(CoreGraphics.kCGInterpolationHigh)
|
context.setInterpolationQuality(CoreGraphics.kCGInterpolationHigh)
|
||||||
new_image_rect = CoreGraphics.CGRectMake(0, 0, x, y)
|
if im1.size[0] <= x:
|
||||||
context.drawImage(new_image_rect, new_image)
|
# for small image just copy:
|
||||||
context.writeToFile(destFile, CoreGraphics.kCGImageFormatPNG)
|
tools.copy_file(srcFile, destFile)
|
||||||
|
else:
|
||||||
|
if y <= 0:
|
||||||
|
# keep ratio :
|
||||||
|
y = int(float(x) * float(source_height) / float(source_width))
|
||||||
|
new_image_rect = CoreGraphics.CGRectMake(0, 0, x, y)
|
||||||
|
context.drawImage(new_image_rect, new_image)
|
||||||
|
tools.create_directory_of_file(destFile)
|
||||||
|
if extension == ".jpeg":
|
||||||
|
context.writeToFile(destFile, CoreGraphics.kCGImageFormatJPEG)
|
||||||
|
elif extension == ".png":
|
||||||
|
context.writeToFile(destFile, CoreGraphics.kCGImageFormatPNG)
|
||||||
|
else:
|
||||||
|
debug.error(" can not manage extention ... : " + destFile)
|
||||||
else:
|
else:
|
||||||
# open an image file (.bmp,.jpg,.png,.gif) you have in the working folder
|
# open an image file (.bmp,.jpg,.png,.gif) you have in the working folder
|
||||||
im1 = image.open(srcFile)
|
im1 = Image.open(srcFile)
|
||||||
# use one of these filter options to resize the image
|
if im1.size[0] <= x:
|
||||||
tmpImage = im1.resize((x, y), Image.ANTIALIAS)
|
# for small image just copy:
|
||||||
tmpImage.save(destFile)
|
tools.copy_file(srcFile, destFile)
|
||||||
|
else:
|
||||||
|
if y <= 0:
|
||||||
|
# keep ratio :
|
||||||
|
y = int(float(x) * float(im1.size[1]) / float(im1.size[0]))
|
||||||
|
# use one of these filter options to resize the image
|
||||||
|
tmpImage = im1.resize((x, y), Image.ANTIALIAS)
|
||||||
|
tools.create_directory_of_file(destFile)
|
||||||
|
tmpImage.save(destFile)
|
||||||
|
@ -372,21 +372,50 @@ class Module:
|
|||||||
lutinMultiprocess.store_command(cmdLine, file_cmd)
|
lutinMultiprocess.store_command(cmdLine, file_cmd)
|
||||||
|
|
||||||
|
|
||||||
|
##
|
||||||
|
## @brief Commands for copying files
|
||||||
|
##
|
||||||
|
def image_to_staging(self, binaryName, target):
|
||||||
|
for source, destination, sizeX, sizeY in self.imageToCopy:
|
||||||
|
extension = source[source.rfind('.'):]
|
||||||
|
if extension != ".png" \
|
||||||
|
and extension != ".jpg" \
|
||||||
|
and sizeX > 0:
|
||||||
|
debug.error("Can not manage image other than .png and jpg to resize : " + source);
|
||||||
|
displaySource = source
|
||||||
|
source = self.originFolder + "/" + source
|
||||||
|
if destination == "":
|
||||||
|
destination = source[source.rfind('/')+1:]
|
||||||
|
debug.verbose("Regenerate Destination : '" + destination + "'")
|
||||||
|
if sizeX > 0:
|
||||||
|
debug.verbose("Image file : " + displaySource + " ==> " + destination + " resize=(" + str(sizeX) + "," + str(sizeY) + ")")
|
||||||
|
fileName, fileExtension = os.path.splitext(self.originFolder+"/" + source)
|
||||||
|
target.add_image_staging(source, destination, sizeX, sizeY)
|
||||||
|
else:
|
||||||
|
debug.verbose("Might copy file : " + displaySource + " ==> " + destination)
|
||||||
|
target.add_file_staging(source, destination)
|
||||||
|
|
||||||
##
|
##
|
||||||
## @brief Commands for copying files
|
## @brief Commands for copying files
|
||||||
##
|
##
|
||||||
def files_to_staging(self, binaryName, target):
|
def files_to_staging(self, binaryName, target):
|
||||||
for element in self.files:
|
for source, destination in self.files:
|
||||||
debug.verbose("Might copy file : " + element[0] + " ==> " + element[1])
|
displaySource = source
|
||||||
target.add_file_staging(self.originFolder+"/"+element[0], element[1])
|
source = self.originFolder + "/" + source
|
||||||
|
if destination == "":
|
||||||
|
destination = source[source.rfind('/')+1:]
|
||||||
|
debug.verbose("Regenerate Destination : '" + destination + "'")
|
||||||
|
# TODO : when destination is missing ...
|
||||||
|
debug.verbose("Might copy file : " + displaySource + " ==> " + destination)
|
||||||
|
target.add_file_staging(source, destination)
|
||||||
|
|
||||||
##
|
##
|
||||||
## @brief Commands for copying files
|
## @brief Commands for copying files
|
||||||
##
|
##
|
||||||
def folders_to_staging(self, binaryName, target):
|
def folders_to_staging(self, binaryName, target):
|
||||||
for element in self.folders:
|
for source, destination in self.folders:
|
||||||
debug.verbose("Might copy folder : " + element[0] + "==>" + element[1])
|
debug.verbose("Might copy folder : " + source + "==>" + destination)
|
||||||
lutinTools.copy_anything_target(target, self.originFolder+"/"+element[0],element[1])
|
lutinTools.copy_anything_target(target, self.originFolder + "/" + source, destination)
|
||||||
|
|
||||||
# call here to build the module
|
# call here to build the module
|
||||||
def build(self, target, packageName):
|
def build(self, target, packageName):
|
||||||
@ -480,6 +509,7 @@ class Module:
|
|||||||
return
|
return
|
||||||
debug.verbose("build tree of " + self.name)
|
debug.verbose("build tree of " + self.name)
|
||||||
# add all the elements (first added only one keep ==> permit to everload sublib element)
|
# add all the elements (first added only one keep ==> permit to everload sublib element)
|
||||||
|
self.image_to_staging(packageName, target)
|
||||||
self.files_to_staging(packageName, target)
|
self.files_to_staging(packageName, target)
|
||||||
self.folders_to_staging(packageName, target)
|
self.folders_to_staging(packageName, target)
|
||||||
#build tree of all submodules
|
#build tree of all submodules
|
||||||
|
@ -3,6 +3,7 @@ import lutinDebug as debug
|
|||||||
import datetime
|
import datetime
|
||||||
import lutinTools
|
import lutinTools
|
||||||
import lutinModule
|
import lutinModule
|
||||||
|
import lutinImage
|
||||||
|
|
||||||
class Target:
|
class Target:
|
||||||
def __init__(self, name, typeCompilator, debugMode, generatePackage, arch, cross, sumulator=False):
|
def __init__(self, name, typeCompilator, debugMode, generatePackage, arch, cross, sumulator=False):
|
||||||
@ -97,19 +98,31 @@ class Target:
|
|||||||
def get_build_mode(self):
|
def get_build_mode(self):
|
||||||
return self.buildMode
|
return self.buildMode
|
||||||
|
|
||||||
def add_file_staging(self, inputFile, outputFile):
|
def add_image_staging(self, inputFile, outputFile, sizeX, sizeY):
|
||||||
for source, dst in self.listFinalFile:
|
for source, dst, x, y in self.listFinalFile:
|
||||||
if dst == outputFile :
|
if dst == outputFile :
|
||||||
debug.verbose("already added : " + outputFile)
|
debug.verbose("already added : " + outputFile)
|
||||||
return
|
return
|
||||||
debug.verbose("add file : '" + inputFile + "' ==> '" + outputFile + "'");
|
debug.verbose("add file : '" + inputFile + "' ==> '" + outputFile + "'");
|
||||||
self.listFinalFile.append([inputFile,outputFile])
|
self.listFinalFile.append([inputFile,outputFile, sizeX, sizeY])
|
||||||
|
|
||||||
|
def add_file_staging(self, inputFile, outputFile):
|
||||||
|
for source, dst, x, y in self.listFinalFile:
|
||||||
|
if dst == outputFile :
|
||||||
|
debug.verbose("already added : " + outputFile)
|
||||||
|
return
|
||||||
|
debug.verbose("add file : '" + inputFile + "' ==> '" + outputFile + "'");
|
||||||
|
self.listFinalFile.append([inputFile,outputFile, -1, -1])
|
||||||
|
|
||||||
def copy_to_staging(self, binaryName):
|
def copy_to_staging(self, binaryName):
|
||||||
baseFolder = self.get_staging_folder_data(binaryName)
|
baseFolder = self.get_staging_folder_data(binaryName)
|
||||||
for source, dst in self.listFinalFile:
|
for source, dst, x, y in self.listFinalFile:
|
||||||
debug.verbose("must copy file : '" + source + "' ==> '" + dst + "'");
|
if x == -1:
|
||||||
lutinTools.copy_file(source, baseFolder+"/"+dst)
|
debug.verbose("must copy file : '" + source + "' ==> '" + dst + "'");
|
||||||
|
lutinTools.copy_file(source, baseFolder+"/"+dst)
|
||||||
|
else:
|
||||||
|
debug.verbose("resize image : '" + source + "' ==> '" + dst + "' size=(" + str(x) + "," + str(y) + ")");
|
||||||
|
lutinImage.resize(source, baseFolder+"/"+dst, x, y)
|
||||||
|
|
||||||
|
|
||||||
def clean_module_tree(self):
|
def clean_module_tree(self):
|
||||||
|
@ -295,7 +295,7 @@ class Target(lutinTarget.Target):
|
|||||||
lutinTools.create_directory_of_file(self.get_staging_folder(pkgName) + "/res/drawable/icon.png");
|
lutinTools.create_directory_of_file(self.get_staging_folder(pkgName) + "/res/drawable/icon.png");
|
||||||
if "ICON" in pkgProperties.keys() \
|
if "ICON" in pkgProperties.keys() \
|
||||||
and pkgProperties["ICON"] != "":
|
and pkgProperties["ICON"] != "":
|
||||||
lutinTools.copy_file(pkgProperties["ICON"], self.get_staging_folder(pkgName) + "/res/drawable/icon.png", True)
|
lutinImage.resize(pkgProperties["ICON"], self.get_staging_folder(pkgName) + "/res/drawable/icon.png", 256, 256)
|
||||||
else:
|
else:
|
||||||
# to be sure that we have all time a resource ...
|
# to be sure that we have all time a resource ...
|
||||||
tmpFile = open(self.get_staging_folder(pkgName) + "/res/drawable/plop.txt", 'w')
|
tmpFile = open(self.get_staging_folder(pkgName) + "/res/drawable/plop.txt", 'w')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user