예제 #1
0
    def convertToLink (self, s, l, t):
        fname = t[1]

        if isImage (fname):
            return '<img src="%s/%s"/>' % (Attachment.attachDir, fname)
        else:
            return '<a href="%s/%s">%s</a>' % (Attachment.attachDir, fname, fname)
예제 #2
0
    def convertToLink (self, s, l, t):
        fname = t[1]

        if isImage (fname):
            return '<img src="%s/%s"/>' % (Attachment.attachDir, fname)
        else:
            return '<a href="%s/%s">%s</a>' % (Attachment.attachDir, fname, fname)
예제 #3
0
    def convertToLink (self, s, l, t):
        fname = t[1]

        if isImage (fname):
            return '<img src="%s/%s"/>' % (PAGE_ATTACH_DIR, fname)
        else:
            return '<a href="%s/%s">%s</a>' % (PAGE_ATTACH_DIR, fname, fname)
예제 #4
0
    def convertToLink (self, s, l, t):
        fname = t[1]

        if isImage (fname):
            return '<IMG SRC="%s/%s"/>' % (Attachment.attachDir, fname)
        else:
            return '<A HREF="%s/%s">%s</A>' % (Attachment.attachDir, fname, fname)
예제 #5
0
 def filterFile (self, fname):
     return isImage (fname)
예제 #6
0
def mosaic(folderName = "img_folder",
		   maxAttempts = ct.MAX_ATTEMPTS,
		   paperSize = ct.SZ_75x50,
		   clusterPow = ct.SZ_CLSTR,
		   padding = ct.DEF_PADDING,
		   color = ct.BCKGRND_CLR,
           debug = False):

	_rld()
	_clearLog()
	pictures = []
	attempt = 0
	minChunkSize = 2**clusterPow
	width = int(round(paperSize[0] / minChunkSize))
	height = int(round(paperSize[1] / minChunkSize))

	# pixel chunk is defined by (lines, columns) format, hence (height, width)
	# when resizing to the closest chunk, keep this in mind
	smallestPixelChunk = (height, width)
	pixelChunks = _getPixelChunk(smallestPixelChunk)
	canvasList = []

	print "pixel chunks: " + str(pixelChunks)

	count = 0
	for path, directory, files in os.walk(folderName):
		for f in files:
			if utils.isImage(f):
				count = count + 1
				p = path + "/" + f
				pictures.append(pct.Picture(f, p, Image.open(p), count))

	print str(len(pictures)) + " pictures to form a mosaic gallery"

	resizedPictures = []
	for i in range(len(pictures)):
		if pictures[i].resizeToClosestChunk(pixelChunks, smallestPixelChunk):
			resizedPictures.append(pictures[i])
		else:
			print "ID: " + str(pictures[i].getID()) + " with name " + pictures[i].getName() +\
				  " could not be resized"
	pictures = resizedPictures

	while not _stopCondition(attempt, maxAttempts):
		attempt = attempt + 1
		print "program at #" + str(attempt) + " attempt ..."
		canvas = ic.ImageCanvas(int(minChunkSize), int(minChunkSize**2), smallestPixelChunk)
		canvas.genMosaicCanvas(pictures)
		if canvas.isComplete():
			canvasList.append(canvas)
			canvas.printClusterCanvas("log", attempt)
	print "... " + str(len(canvasList)) + " completed image canvas"

	if len(canvasList) > 0:
		highest = _getHighest(canvasList)
		highest.printClusterCanvas("", "_highest")
		print str(highest.getCanvasRating()) + " is the highest rating of this simulation"

		pixelCanvas = _pasteImagesInCanvas(paperSize, highest, padding, color, debug)
		_savePixelCanvas(pixelCanvas)
	else:
		print "simulation endend without finding a solution for the problem ..."
예제 #7
0
 def filterFile (self, fname):
     return isImage (fname)