├── README.md ├── display.png └── imageEd ├── MoveWindow.py ├── __pycache__ └── colors.cpython-34.pyc ├── canvasdraw.py ├── color_palette.py ├── colorful-italy.jpg ├── colors.py ├── icons ├── brush-resize.png ├── cam.png ├── folder-open-resize.png └── tick.png ├── imged.py └── resizeimg.py /README.md: -------------------------------------------------------------------------------- 1 | # Image-Editor-Python-tkinter 2 | 3 | ![](https://github.com/HarowitzBlack/Image-Editor-Python-tkinter/blob/master/display.png) 4 | -------------------------------------------------------------------------------- /display.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamnottheway/Image-Editor-Python-tkinter/2439e5f90f5dc5abb470c893ac233bd68cc98916/display.png -------------------------------------------------------------------------------- /imageEd/MoveWindow.py: -------------------------------------------------------------------------------- 1 | # @HarowitzBlack -> author 2 | # A MOVABLE TOP AND A SEXY CLOSE BUTTON FOR THE NAKED BITCH!!! 3 | # @candiedpussy :p -> awesome name, isn't it? NEVER USE IT! I'll sue you for intellectual 4 | # property theft!!! lol :o, (.)(.) 5 | 6 | 7 | from tkinter import * 8 | from PIL import ImageTk, Image 9 | 10 | BG_COLOR = '#24272b' 11 | 12 | class MovableWindow(): 13 | 14 | ''' 15 | CANVAS WHICH IS MOVABLE WHEN CLICKED AND DRAGGED 16 | ''' 17 | 18 | def __init__(self,parent): 19 | self.parent = parent 20 | # create a canvas which is movable 21 | self.Holder = Frame(self.parent,width = 260,height=20,bg = BG_COLOR) 22 | self.Holder.grid(row = 0,column = 1,ipady=2) 23 | self.MovableCanvas = Canvas(self.Holder,width = 260,height = 25,\ 24 | bg = BG_COLOR,highlightthickness=0) 25 | self.MovableCanvas.bind('',self.ClickTopLevel) 26 | self.MovableCanvas.bind('',self.DragTopLevel) 27 | self.MovableCanvas.grid(row = 0,column = 1,sticky = W) 28 | 29 | # CLOSE WINDOW BUTTON 30 | self.closeXmarker = ImageTk.PhotoImage(file="icons/cc.png") 31 | self.closeBrushWin = Button(self.Holder,width = 20,height=20,bd = 0,bg = BG_COLOR,command=self.parent.withdraw,\ 32 | cursor='hand2',activebackground=BG_COLOR,highlightthickness=0) 33 | self.closeBrushWin.config(image=self.closeXmarker) 34 | self.closeBrushWin.grid(row=0,column=2,sticky=E,padx = 7) 35 | 36 | def ClickTopLevel(self,event): 37 | self.TopLevelXPos,self.TopLevelYPos = event.x,event.y 38 | 39 | def DragTopLevel(self,event): 40 | #print(event) 41 | self.childWin = self.parent 42 | x = self.childWin.winfo_pointerx() - self.TopLevelXPos 43 | y = self.childWin.winfo_pointery() - self.TopLevelYPos 44 | #self.childWin.config(cursor = 'fleur') 45 | self.childWin.geometry('+{x}+{y}'.format(x=x,y=y)) -------------------------------------------------------------------------------- /imageEd/__pycache__/colors.cpython-34.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamnottheway/Image-Editor-Python-tkinter/2439e5f90f5dc5abb470c893ac233bd68cc98916/imageEd/__pycache__/colors.cpython-34.pyc -------------------------------------------------------------------------------- /imageEd/canvasdraw.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | from colors import COLORS 3 | import random 4 | 5 | root = Tk() 6 | root.resizable(0,0) 7 | 8 | def Draw(event): 9 | x,y = event.x,event.y 10 | point = Sheet.create_oval(x,y,x+50,y+50,fill = COLORS[random.randint(0,len(COLORS)-1)]) 11 | del point 12 | 13 | def clearscrn(): 14 | Sheet.delete("all") 15 | 16 | Sheet = Canvas(root,bg = "white",width = 400,height = 400) 17 | Sheet.pack() 18 | 19 | btn = Button(root,text="clear all",command=clearscrn) 20 | btn.pack() 21 | 22 | root.bind('',Draw) 23 | root.mainloop() -------------------------------------------------------------------------------- /imageEd/color_palette.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | from colors import COLORS 3 | import random 4 | 5 | def get_color(*args): 6 | current_color = ColorPaletteCanvas.itemcget("current","tags") 7 | print(current_color) 8 | 9 | root = Tk() 10 | root.geometry("300x300+300+200") 11 | root.config(bg="#333") 12 | root.resizable(0,0) 13 | root.title("color pallette") 14 | 15 | ColorPaletteCanvas = Canvas(root,width = 210,height = 220,bg = 'white',cursor = 'tcross') 16 | ColorPaletteCanvas.grid(row = 0,column=1,padx = 10,pady = 10) 17 | # colors inside the palette 18 | x_pos = 0 19 | y_pos = 0 20 | # final x coord of the canvas is 200 21 | # and y coord is 100. -20 from them 22 | for c in COLORS: 23 | colorsInside = ColorPaletteCanvas.create_rectangle(x_pos,y_pos,x_pos+10,y_pos+10,fill = c,tags=("{0}".format(c))) 24 | #showing all the colors on the screen 25 | x_pos += 10 26 | if x_pos > 200: 27 | y_pos += 10 28 | x_pos = 0 29 | 30 | # current is a keyword. It points to the current object. Alternative: CURRENT 31 | # gets the current clicked color from the palette 32 | ColorPaletteCanvas.tag_bind("current",'',get_color) 33 | #print(ColorPaletteCanvas.find_withtag(CURRENT[0]) 34 | # prints what typeof item it is 35 | #print(ColorPaletteCanvas.type(colorsInside)) 36 | #print(tags) 37 | root.mainloop() -------------------------------------------------------------------------------- /imageEd/colorful-italy.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamnottheway/Image-Editor-Python-tkinter/2439e5f90f5dc5abb470c893ac233bd68cc98916/imageEd/colorful-italy.jpg -------------------------------------------------------------------------------- /imageEd/colors.py: -------------------------------------------------------------------------------- 1 | COLORS = ['snow', 'ghost white', 'white smoke', 'gainsboro', 'floral white', 'old lace', 2 | 'linen', 'antique white', 'papaya whip', 'blanched almond', 'bisque', 'peach puff', 3 | 'navajo white', 'lemon chiffon', 'mint cream', 'azure', 'alice blue', 'lavender', 4 | 'lavender blush', 'misty rose', 'dark slate gray', 'dim gray', 'slate gray', 5 | 'light slate gray', 'gray', 'light grey', 'midnight blue', 'navy', 'cornflower blue', 'dark slate blue', 6 | 'slate blue', 'medium slate blue', 'light slate blue', 'medium blue', 'royal blue', 'blue', 7 | 'dodger blue', 'deep sky blue', 'sky blue', 'light sky blue', 'steel blue', 'light steel blue', 8 | 'light blue', 'powder blue', 'pale turquoise', 'dark turquoise', 'medium turquoise', 'turquoise', 9 | 'cyan', 'light cyan', 'cadet blue', 'medium aquamarine', 'aquamarine', 'dark green', 'dark olive green', 10 | 'dark sea green', 'sea green', 'medium sea green', 'light sea green', 'pale green', 'spring green', 11 | 'lawn green', 'medium spring green', 'green yellow', 'lime green', 'yellow green', 12 | 'forest green', 'olive drab', 'dark khaki', 'khaki', 'pale goldenrod', 'light goldenrod yellow', 13 | 'light yellow', 'yellow', 'gold', 'light goldenrod', 'goldenrod', 'dark goldenrod', 'rosy brown', 14 | 'indian red', 'saddle brown', 'sandy brown', 15 | 'dark salmon', 'salmon', 'light salmon', 'orange', 'dark orange', 16 | 'coral', 'light coral', 'tomato', 'orange red', 'red', 'hot pink', 'deep pink', 'pink', 'light pink', 17 | 'pale violet red', 'maroon', 'medium violet red', 'violet red', 18 | 'medium orchid', 'dark orchid', 'dark violet', 'blue violet', 'purple', 'medium purple', 19 | 'thistle', 'snow2', 'snow3', 20 | 'snow4', 'seashell2', 'seashell3', 'seashell4', 'AntiqueWhite1', 'AntiqueWhite2', 21 | 'AntiqueWhite3', 'AntiqueWhite4', 'bisque2', 'bisque3', 'bisque4', 'PeachPuff2', 22 | 'PeachPuff3', 'PeachPuff4', 'NavajoWhite2', 'NavajoWhite3', 'NavajoWhite4', 23 | 'LemonChiffon2', 'LemonChiffon3', 'LemonChiffon4', 'cornsilk2', 'cornsilk3', 24 | 'cornsilk4', 'ivory2', 'ivory3', 'ivory4', 'honeydew2', 'honeydew3', 'honeydew4', 25 | 'LavenderBlush2', 'LavenderBlush3', 'LavenderBlush4', 'MistyRose2', 'MistyRose3', 26 | 'MistyRose4', 'azure2', 'azure3', 'azure4', 'SlateBlue1', 'SlateBlue2', 'SlateBlue3', 27 | 'SlateBlue4', 'RoyalBlue1', 'RoyalBlue2', 'RoyalBlue3', 'RoyalBlue4', 'blue2', 'blue4', 28 | 'DodgerBlue2', 'DodgerBlue3', 'DodgerBlue4', 'SteelBlue1', 'SteelBlue2', 29 | 'SteelBlue3', 'SteelBlue4', 'DeepSkyBlue2', 'DeepSkyBlue3', 'DeepSkyBlue4', 30 | 'SkyBlue1', 'SkyBlue2', 'SkyBlue3', 'SkyBlue4', 'LightSkyBlue1', 'LightSkyBlue2', 31 | 'LightSkyBlue3', 'LightSkyBlue4', 'SlateGray1', 'SlateGray2', 'SlateGray3', 32 | 'SlateGray4', 'LightSteelBlue1', 'LightSteelBlue2', 'LightSteelBlue3', 33 | 'LightSteelBlue4', 'LightBlue1', 'LightBlue2', 'LightBlue3', 'LightBlue4', 34 | 'LightCyan2', 'LightCyan3', 'LightCyan4', 'PaleTurquoise1', 'PaleTurquoise2', 35 | 'PaleTurquoise3', 'PaleTurquoise4', 'CadetBlue1', 'CadetBlue2', 'CadetBlue3', 36 | 'CadetBlue4', 'turquoise1', 'turquoise2', 'turquoise3', 'turquoise4', 'cyan2', 'cyan3', 37 | 'cyan4', 'DarkSlateGray1', 'DarkSlateGray2', 'DarkSlateGray3', 'DarkSlateGray4', 38 | 'aquamarine2', 'aquamarine4', 'DarkSeaGreen1', 'DarkSeaGreen2', 'DarkSeaGreen3', 39 | 'DarkSeaGreen4', 'SeaGreen1', 'SeaGreen2', 'SeaGreen3', 'PaleGreen1', 'PaleGreen2', 40 | 'PaleGreen3', 'PaleGreen4', 'SpringGreen2', 'SpringGreen3', 'SpringGreen4', 41 | 'green2', 'green3', 'green4', 'chartreuse2', 'chartreuse3', 'chartreuse4', 42 | 'OliveDrab1', 'OliveDrab2', 'OliveDrab4', 'DarkOliveGreen1', 'DarkOliveGreen2', 43 | 'DarkOliveGreen3', 'DarkOliveGreen4', 'khaki1', 'khaki2', 'khaki3', 'khaki4', 44 | 'LightGoldenrod1', 'LightGoldenrod2', 'LightGoldenrod3', 'LightGoldenrod4', 45 | 'LightYellow2', 'LightYellow3', 'LightYellow4', 'yellow2', 'yellow3', 'yellow4', 46 | 'gold2', 'gold3', 'gold4', 'goldenrod1', 'goldenrod2', 'goldenrod3', 'goldenrod4', 47 | 'DarkGoldenrod1', 'DarkGoldenrod2', 'DarkGoldenrod3', 'DarkGoldenrod4', 48 | 'RosyBrown1', 'RosyBrown2', 'RosyBrown3', 'RosyBrown4', 'IndianRed1', 'IndianRed2', 49 | 'IndianRed3', 'IndianRed4', 'sienna1', 'sienna2', 'sienna3', 'sienna4', 'burlywood1', 50 | 'burlywood2', 'burlywood3', 'burlywood4', 'wheat1', 'wheat2', 'wheat3', 'wheat4', 'tan1', 51 | 'tan2', 'tan4', 'chocolate1', 'chocolate2', 'chocolate3', 'firebrick1', 'firebrick2', 52 | 'firebrick3', 'firebrick4', 'brown1', 'brown2', 'brown3', 'brown4', 'salmon1', 'salmon2', 53 | 'salmon3', 'salmon4', 'LightSalmon2', 'LightSalmon3', 'LightSalmon4', 'orange2', 54 | 'orange3', 'orange4', 'DarkOrange1', 'DarkOrange2', 'DarkOrange3', 'DarkOrange4', 55 | 'coral1', 'coral2', 'coral3', 'coral4', 'tomato2', 'tomato3', 'tomato4', 'OrangeRed2', 56 | 'OrangeRed3', 'OrangeRed4', 'red2', 'red3', 'red4', 'DeepPink2', 'DeepPink3', 'DeepPink4', 57 | 'HotPink1', 'HotPink2', 'HotPink3', 'HotPink4', 'pink1', 'pink2', 'pink3', 'pink4', 58 | 'LightPink1', 'LightPink2', 'LightPink3', 'LightPink4', 'PaleVioletRed1', 59 | 'PaleVioletRed2', 'PaleVioletRed3', 'PaleVioletRed4', 'maroon1', 'maroon2', 60 | 'maroon3', 'maroon4', 'VioletRed1', 'VioletRed2', 'VioletRed3', 'VioletRed4', 61 | 'magenta2', 'magenta3', 'magenta4', 'orchid1', 'orchid2', 'orchid3', 'orchid4', 'plum1', 62 | 'plum2', 'plum3', 'plum4', 'MediumOrchid1', 'MediumOrchid2', 'MediumOrchid3', 63 | 'MediumOrchid4', 'DarkOrchid1', 'DarkOrchid2', 'DarkOrchid3', 'DarkOrchid4', 64 | 'purple1', 'purple2', 'purple3', 'purple4', 'MediumPurple1', 'MediumPurple2', 65 | 'MediumPurple3', 'MediumPurple4', 'thistle1', 'thistle2', 'thistle3', 'thistle4', 66 | 'gray1', 'gray2', 'gray3', 'gray4', 'gray5', 'gray6', 'gray7', 'gray8', 'gray9', 'gray10', 67 | 'gray11', 'gray12', 'gray13', 'gray14', 'gray15', 'gray16', 'gray17', 'gray18', 'gray19', 68 | 'gray20', 'gray21', 'gray22', 'gray23', 'gray24', 'gray25', 'gray26', 'gray27', 'gray28', 69 | 'gray29', 'gray30', 'gray31', 'gray32', 'gray33', 'gray34', 'gray35', 'gray36', 'gray37', 70 | 'gray38', 'gray39', 'gray40', 'gray42', 'gray43', 'gray44', 'gray45', 'gray46', 'gray47', 71 | 'gray48', 'gray49', 'gray50', 'gray51', 'gray52', 'gray53', 'gray54', 'gray55', 'gray56', 72 | 'gray57', 'gray58', 'gray59', 'gray60', 'gray61', 'gray62', 'gray63', 'gray64', 'gray65', 73 | 'gray66', 'gray67', 'gray68', 'gray69', 'gray70', 'gray71', 'gray72', 'gray73', 'gray74', 74 | 'gray75', 'gray76', 'gray77', 'gray78', 'gray79', 'gray80', 'gray81', 'gray82', 'gray83', 75 | 'gray84', 'gray85', 'gray86', 'gray87', 'gray88', 'gray89', 'gray90', 'gray91', 'gray92', 76 | 'gray93', 'gray94', 'gray95', 'gray97', 'gray98', 'gray99'] -------------------------------------------------------------------------------- /imageEd/icons/brush-resize.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamnottheway/Image-Editor-Python-tkinter/2439e5f90f5dc5abb470c893ac233bd68cc98916/imageEd/icons/brush-resize.png -------------------------------------------------------------------------------- /imageEd/icons/cam.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamnottheway/Image-Editor-Python-tkinter/2439e5f90f5dc5abb470c893ac233bd68cc98916/imageEd/icons/cam.png -------------------------------------------------------------------------------- /imageEd/icons/folder-open-resize.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamnottheway/Image-Editor-Python-tkinter/2439e5f90f5dc5abb470c893ac233bd68cc98916/imageEd/icons/folder-open-resize.png -------------------------------------------------------------------------------- /imageEd/icons/tick.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamnottheway/Image-Editor-Python-tkinter/2439e5f90f5dc5abb470c893ac233bd68cc98916/imageEd/icons/tick.png -------------------------------------------------------------------------------- /imageEd/imged.py: -------------------------------------------------------------------------------- 1 | import os 2 | import random 3 | import numpy as np 4 | from tkinter import * 5 | from PIL import ImageTk, Image 6 | from tkinter import filedialog 7 | from skimage import io,color 8 | from colors import COLORS 9 | from MoveWindow import MovableWindow 10 | 11 | 12 | 13 | BG_COLOR = '#24272b' 14 | SIZE = [800,600] 15 | 16 | IMAGE_PATH = "empty" 17 | 18 | 19 | class ImageOperations(): 20 | # basic image operations 21 | def __init__(self,path2img): 22 | self.path2img = path2img 23 | 24 | # converts an image as an array 25 | def GetImageAsArray(self): 26 | self.image = self.path2img 27 | self.img2ar = [] 28 | try: 29 | self.img2ar = io.imread(self.image) 30 | except Exception as e: 31 | print(e) 32 | return self.img2ar 33 | 34 | # converts the array to an image and saves 35 | def SaveArray2Img(self,array,path = '/home/freezer9/Desktop/',imageName='ebab.png'): 36 | self.array,self.imageName,self.path = array,imageName,path 37 | self.path = self.path + self.imageName 38 | io.imsave(self.path,self.array) 39 | print("Image saved @ {}".format(self.path)) 40 | 41 | 42 | class ImageEffects(): 43 | def __init__(self): 44 | pass 45 | 46 | def AddaBox(self,array,row,col,colorAr): 47 | self.array,self.row,self.col,self.colorAr = array,row,col,colorAr 48 | self.array[:self.row,:self.col] = self.colorAr 49 | print('Added a box') 50 | return self.array 51 | 52 | def ColorGradient(self,array,rainbwRow,rowHeight = 'NONE'): 53 | # creates a spectrum of random colors 54 | # rainbwRow is the height of the box, max height depends on the image dimensions 55 | self.rowHeight = rowHeight 56 | self.rainbwRow = rainbwRow 57 | if self.rowHeight == 'MAX': 58 | self.rainbwRow = max(array.shape) 59 | self.array = array 60 | while self.rainbwRow > 0: 61 | self.array = self.AddaBox(self.array,self.rainbwRow,250,[random.randint(0,255),random.randint(0,255),random.randint(0,255)]) 62 | self.rainbwRow -= 2 63 | return self.array 64 | 65 | def ColorPixelate(self,array): 66 | # changew the image into random color spots 67 | self.array = array 68 | self.maxNum = max(self.array.shape) 69 | for row in range(0,self.maxNum): 70 | for col in range(0,self.maxNum): 71 | # randomly change the color of 1px 72 | self.array[row,col] = [random.randint(0,255),random.randint(0,255),random.randint(0,255)] 73 | return self.array 74 | 75 | def Convert2Gray(self,array): 76 | # converts to grayscale 77 | self.array = array 78 | return color.rgb2gray(self.array) 79 | 80 | def grayscaleFilter1(self,array,TintMagnitude): 81 | # dim the gray scale or brighten it up 82 | # gray scale values range from 0 - 1 (sigmoid function to make a number range from 0-1) 83 | self.array,self.TintMagnitude = array,TintMagnitude 84 | # convert to gray 85 | self.array = self.Convert2Gray(self.array) 86 | self.array = (self.TintMagnitude * self.array) 87 | return self.array 88 | 89 | 90 | # EDIT PICTURE 91 | class PictureEdit(MovableWindow): 92 | 93 | def __init__(self,parent): 94 | self.parent = parent 95 | self.PictureEditWin() 96 | 97 | def PictureEditWin(self): 98 | self.PicEdWin = Toplevel(self.parent) 99 | self.PicEdWin.title("Picture Effects") 100 | self.PicEdWin.geometry("300x300+900+150") 101 | self.PicEdWin.config(bg = BG_COLOR) 102 | self.PicEdWin.resizable(0,0) 103 | self.PicEdWin.overrideredirect(1) 104 | MovableWindow.__init__(self,self.PicEdWin) 105 | self.grayLab = Label(self.PicEdWin,text = "grayscale",bg=BG_COLOR,fg = "#fff") 106 | self.grayLab.grid(row = 1,column=1,sticky=W,padx = 10) 107 | self.grayscaleSlider = Scale(self.PicEdWin, from_=0, to=100,orient=HORIZONTAL,\ 108 | width = 10,bd = 0,bg = "#333",fg = 'white',length = 250,highlightthickness=1) 109 | self.grayscaleSlider.grid(row = 2,column=1) 110 | 111 | self.okButton = Button(self.PicEdWin,text = "ok",command = self.getGrayScaleValue,bd = 0,bg = BG_COLOR,width = 1,\ 112 | height = 1).grid(row = 3,column=1,\ 113 | ipadx = 1,ipady= 0) 114 | 115 | def getGrayScaleValue(self): 116 | # return the slider value which ranges btwn 0 - 1 117 | return self.grayscaleSlider.get()/100 118 | 119 | # find a way to get the image location into this stuff 120 | def ConvertToGray(self,imPath): 121 | self.graytintMag = self.getGrayScaleValue() 122 | self.imPath = imPath 123 | self.imgOp = ImageOperations(self.imPath) 124 | self.imAr = self.imgOp.GetImageAsArray() 125 | self.imEffects = ImageEffects() 126 | self.imEffects.grayscaleFilter1(self.imAr,self.graytintMag) 127 | 128 | # Main Parent window class 129 | class WindowApp(PictureEdit): 130 | 131 | def __init__(self,master): 132 | self.master = master 133 | self.master.geometry("800x600+200+100") 134 | self.master.config(bg = BG_COLOR) 135 | self.master.title('ImgEd') 136 | self.master.resizable(0,0) 137 | # container to hold the tools 138 | self.ToolBoxFrame = Frame(self.master,width = SIZE[0],height= 50,bg="blue") 139 | self.ToolBoxFrame.grid(row = 1,column= 1,padx = 10,pady = 5,sticky = W) 140 | # add icon to open img button 141 | self.openImgBtn = Button(self.ToolBoxFrame,command = self.open_img,width = 20,height = 20,bd = 0,cursor = "hand2") 142 | self.FolderOpenIcon = ImageTk.PhotoImage(file="icons/folder-open-resize.png") 143 | self.openImgBtn.config(image= self.FolderOpenIcon) 144 | self.openImgBtn.grid(row = 1,column=2,sticky = W) 145 | # create a button and add an icon 146 | self.BrushButton = Button(self.ToolBoxFrame,width = 20,height = 20,text = 'bb',bd = 0,cursor = "hand2",command = self.StartDraw) 147 | self.BrushIcon = ImageTk.PhotoImage(file="icons/brush-resize.png") 148 | self.BrushButton.config(image = self.BrushIcon) 149 | self.BrushButton.grid(row = 1,column = 3) 150 | # camera edit button 151 | self.PicEditButton = Button(self.ToolBoxFrame,text = "C",width = 20,height = 20,bd = 0,cursor='hand2',command=self.ShowPicEditor) 152 | self.PicEditIcon = ImageTk.PhotoImage(file="icons/cam.png") 153 | self.PicEditButton.config(image = self.PicEditIcon) 154 | self.PicEditButton.grid(row = 1,column = 4) 155 | 156 | def ShowPicEditor(self): 157 | super().__init__(self.master) 158 | 159 | 160 | def openfn(self): 161 | self.filename = filedialog.askopenfilename(title='open') 162 | return self.filename 163 | 164 | def open_img(self): 165 | try: 166 | self.path = self.openfn() 167 | self.master.title(self.path) 168 | self.DrawCanvas = Canvas(self.master,width = SIZE[0],height = SIZE[1],bg = '#333') 169 | self.DrawCanvas.grid(row = 2,column = 1) 170 | self.img = Image.open(self.path) 171 | self.img = self.img.resize((700, 500), Image.ANTIALIAS) 172 | # image converted to photoimg object 173 | self.img = ImageTk.PhotoImage(self.img) 174 | self.DrawCanvas.create_image(SIZE[0]/2,SIZE[1]/2,image=self.img) 175 | # convert the image into an numpy array for further processing 176 | self.imgIO = ImageOperations(self.path) 177 | self.imageAsArray = self.imgIO.GetImageAsArray() 178 | except: 179 | # if the open file dialog box is closed without opening any image just ignore the error 180 | pass 181 | 182 | def GetCurrentPath(self): 183 | return self.path 184 | 185 | # function to draw stuff on the canvas 186 | def StartDraw(self): 187 | self.BrushWin = EditWindow(self.master) 188 | self.BrushWin.BrushEffects() 189 | # callback function to draw the stuff 190 | self.master.bind('',self.Draw) 191 | 192 | def Draw(self,event,thickness = 5): 193 | try: 194 | self.event = event 195 | # gets the current size of the brush 196 | self.thickness = self.BrushWin.refreshBrushthk() 197 | self.DrawCanvas.config(cursor="tcross") 198 | self.x,self.y = self.event.x,self.event.y 199 | self.point = self.DrawCanvas.create_oval(self.x,self.y,self.x+self.thickness,self.y+self.thickness,fill = COLORS[random.randint(0,len(COLORS)-1)]) 200 | del self.point 201 | except: 202 | print("NOTHING TO DRAW ON YOU DUMBFUCK!") 203 | 204 | 205 | class EditWindow(MovableWindow): 206 | 207 | def __init__(self,parent): 208 | self.parent = parent 209 | self.TopLevelXPos = 0 210 | self.TopLevelYPos = 0 211 | #self.path = path 212 | 213 | def BrushEffects(self): 214 | self.editWin = Toplevel(self.parent) 215 | self.editWin.title("Brush Effects") 216 | self.editWin.geometry("300x300+900+150") 217 | self.editWin.config(bg = BG_COLOR) 218 | self.editWin.resizable(0,0) 219 | self.editWin.overrideredirect(1) 220 | # bind the mouse-button to the window, so that when 221 | # the user holds the window it moves 222 | # create a canvas to drag the window, so that it doesn't affect oher widgets 223 | # call the movable window class 224 | MovableWindow.__init__(self,self.editWin) 225 | # BRUSH-THICKNESS 226 | self.thicknessLabel = Label(self.editWin,text = "Thickness :",bg = BG_COLOR,fg="snow") 227 | self.thicknessLabel.grid(row = 1,column=1,sticky = W) 228 | # slider 229 | self.BrushThickness = Scale(self.editWin, from_=0, to=100,orient=HORIZONTAL,width = 10,bd = 0,bg = "#333",fg = 'white',\ 230 | length = 250) 231 | self.BrushThickness.grid(row=2,column=1,padx = 5) 232 | # refresh thickness button 233 | self.RefreshThicknessBtn = ImageTk.PhotoImage(file="icons/tick.png") 234 | self.SetBrushThicknessBtn = Button(self.editWin,width=20,height=20,text = 'v',bd = 0,command=self.refreshBrushthk,cursor = "hand2") 235 | self.SetBrushThicknessBtn.config(image = self.RefreshThicknessBtn) 236 | self.SetBrushThicknessBtn.grid(row=2,column=2,padx = 5) 237 | 238 | # COLOR PALETTE 239 | self.ColorPaletteLabel = Label(self.editWin,text = 'Color Palette',fg = 'white',bg = BG_COLOR) 240 | self.ColorPaletteLabel.grid(row = 3,column = 1,pady = 5,sticky =W) 241 | self.ColorPaletteCanvas = Canvas(self.editWin,width = 210,height = 100,bg = 'white',cursor = 'tcross') 242 | self.ColorPaletteCanvas.grid(row = 4,column=1,pady = 2) 243 | # colors inside the palette 244 | x_pos = 0 245 | y_pos = 0 246 | # final x coord of the canvas is 200 247 | # and y coord is 100. -20 from them 248 | for c in COLORS: 249 | self.colorsInside = self.ColorPaletteCanvas.create_rectangle(x_pos,y_pos,x_pos+10,y_pos+10,fill = c) 250 | #showing all the colors on the screen 251 | x_pos += 10 252 | if x_pos > 200: 253 | y_pos += 10 254 | x_pos = 0 255 | 256 | def refreshBrushthk(self): 257 | # store the thickness to use in the label 258 | self.LabelThickness = self.BrushThickness.get() 259 | self.thicknessLabel.config(text = "Thickness : {}".format(self.LabelThickness)) 260 | return self.BrushThickness.get() 261 | 262 | 263 | 264 | 265 | def Tester(imgPath): 266 | im = ImageOperations(imgPath) 267 | effects = ImageEffects() 268 | bab = im.GetImageAsArray() 269 | original_image = bab # store a copy of the array 270 | imageShape = bab.shape 271 | imageRow,imageCol = imageShape[0],imageShape[1] 272 | #bab = effects.AddaBox(bab,startRow,250,[0,0,0]) 273 | #bab = effects.ColorGradient(bab,250,'MAX') 274 | #bab = effects.ColorPixelate(bab) 275 | bab = effects.brightORdimGray(bab,[0.5]) 276 | im.SaveArray2Img(bab) 277 | os.system('gnome-open {}\n\n'.format('ebab.png')) 278 | 279 | def TestSigmoid(x): 280 | return 1.0 / (1.0 + np.exp(-1.0 * x)) 281 | 282 | def run(): 283 | root = Tk() 284 | win = WindowApp(root) 285 | root.mainloop() 286 | 287 | #Tester('baboon.png') 288 | run() 289 | 290 | 291 | 292 | -------------------------------------------------------------------------------- /imageEd/resizeimg.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | from tkinter import filedialog 3 | from PIL import ImageTk, Image 4 | import random 5 | 6 | def openfn(): 7 | filename = filedialog.askopenfilename(title='open') 8 | return filename 9 | 10 | def resizeImage(): 11 | path = openfn() 12 | image = Image.open(path) 13 | image = image.resize((20,20),Image.ANTIALIAS) 14 | image.save('{}.png'.format(random.randint(12345,21322))) 15 | print('resized and Saved!') 16 | 17 | root = Tk() 18 | root.resizable(0,0) 19 | root.geometry("200x200") 20 | btn = Button(root,text='resize image',command=resizeImage).pack() 21 | root.mainloop() 22 | 23 | 24 | --------------------------------------------------------------------------------