def generateAdImage(): dirAndFiles = os.listdir(constConfig.adPathResource) for fileName in dirAndFiles: resourceImageFileName = constConfig.adPathResource+os.sep+fileName # resource image file path name if(os.path.isfile(resourceImageFileName)): if(ImageExtendName.isExtendName(os.path.splitext(fileName)[1])): generateFileName = os.path.join(constConfig.adPathTarget,fileName+constConfig.imageExtentName) if(os.path.isfile(generateFileName) is False): logging.info(generateFileName) im = Image.open(resourceImageFileName) im.save(generateFileName,constConfig.imageFormat,quality = constConfig.imageQuality)
def ad(timestamp): sql = """ select ad_id,ad_code from shouji_ad WHERE end_time>=%s """ %timestamp db = DbMysql() db.cursor.execute(sql) rows = db.cursor.fetchall() for row in rows: realPath = os.path.join(constConfig.adPathResource,row['ad_code']) if(os.path.isfile(realPath)): if(ImageExtendName.isExtendName(os.path.splitext(row['ad_code'])[1])): im = Image.open(realPath) generateFileName = os.path.join(constConfig.adPathTarget,row['ad_code'] + constConfig.imageExtentName) logging.info(generateFileName) im.save(generateFileName,constConfig.imageFormat,quality = constConfig.imageQuality)
def multiGenerateImage(dirPath): dirAndFiles = os.listdir(dirPath) for fileName in dirAndFiles: realFileName = os.path.join(dirPath,fileName) if(os.path.isfile(realFileName)): if(ImageExtendName.isExtendName(os.path.splitext(fileName)[1])): generateFileName = realFileName + constConfig.imageExtentName if(os.path.isfile(generateFileName) is False): logging.info(generateFileName) im = Image.open(realFileName) im.save(generateFileName,constConfig.imageFormat, quality = constConfig.imageQuality) elif(os.path.isdir(realFileName)): multiGenerateImage(realFileName)