In this article, the example for you to share the python zoom in the picture and draw the specific code of the square, for your reference, the details are as follows
1, Python zoom pictures and draw squares algorithm
#!C:/Python27 # -*- coding: utf-8 -*- import os import sys from PIL import Image,ImageDraw def make_doc_data(lf): #li, ri = make_regalur_image((lf)), make_regalur_image((rf)) #two images method li = (lf) size = (256, 256) # Geometric transformations, all converted to 256*256 pixel size li =(size).convert('RGB') (lf + '_regalur.png')#convert image format:(''), save temporary #(rf + '_regalur.png')#img object to hard disk fd = open('', 'w')The #stat module does statistics on random variables, stat is used to calculate the expected value and variance of a random variable #That's the key. Map the results of the histogram. #('\n'.join(l + ',' + r for l, r in zip(map(str, ()), map(str, ())))) (','.join(map(str, ()))) () li = ('RGB') # with the save object, which is converted to the format draw = (li) for i in xrange(0, 256, 64): ((0, i, 256, i), fill = '#ff0000') ((i, 0, i, 256), fill = '#ff0000') #Delineate from start to finish! Random distribution of color delineation by painting each column red #usage:(Surface, color, start_pos, end_pos, width=1) (lf + '_lines.png') make_doc_data('testpic/')
2, zoom in and out of the picture of several methods
#!C:/Python27 #coding=utf-8 import pytesseract from pytesser import * from PIL import Image,ImageEnhance,ImageFilter import os import fnmatch import re,time import urllib, random #Modify the file name #("E:/pythonScript/Model/font/","E:/pythonScript/Model/font/") def CutImg(): img = ('.//').convert('L') print w, h = #rowheight = h // rownum #colwidth = w // colnum #() j = 10 for i in range(4): x = 10 + i*24 #The x,y coordinates of the CAPTCHA. y = 6 ((x-4, y,x+6, y+14)).save("pic/%" % j) print "j=",j j += 1 () infile = ('.//testpic//') outfile = ('.//testpic//') def fixed_size(infile): """Processing pictures to a fixed size""" im = (infile) size = (256, 256) im2 =(size).convert('RGB') out = (size,) (outfile) print u"\n Enlarge the picture at a fixed size. Processing is complete." def resize_by_width(w_divide_h): """Reduce by the width in the desired proportion.""" im = (infile) print (x, y) = x_s = x print x_s y_s = x/w_divide_h #w_divide_h > x print y_s out = ((x_s, y_s), ) (outfile) def resize_by_height(w_divide_h): """Scale to height as desired.""" im = (infile) (x, y) = print x_s = y*w_divide_h y_s = y out = ((x_s, y_s), ) (outfile,quality = 95,dpi=(72, 72)) def cut_by_ratio(width, height): """Split by image aspect ratio""" im = (infile) width = float(width) height = float(height) (x, y) = if width > height: region = (0, int((y-(y * (height / width)))/2), x, int((y+(y * (height / width)))/2)) elif width < height: region = (int((x-(x * (width / height)))/2), 0, int((x+(x * (width / height)))/2), y) else: region = (0, 0, x, y) #Crop Pictures crop_img = (region) #Save the cropped image crop_img.save(outfile) def Lager(size): im = (infile) im_resized=(size, ) im_resized.save(outfile,quality = 95,dpi=(72, 72)) def *img(): """ Fuzzy Pictures """ im = (infile) im2 = () (outfile) """ Storage for multiple icon sizes """ image_size = [512,250,144,140,128,120,108,100,88,72,48,32,28] def create_icon(): for size in image_size: '''''pri_image = ("") pri_image.thumbnail((size,size)) image_name = "icon_%"%(size) pri_image.save(image_name)''' pri_image = (infile) pri_image.resize((size,size), ).save("testpic/icom_%"%(size)) fixed_size(infile) #resize_by_width(10) #resize_by_height(1) #cut_by_ratio(50,20) #Lager(256) #*img() #create_icon() #CutImg()
This is the whole content of this article.