issue87:python
                Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| issue87:python [2015/01/05 21:56] – [7] fredphil91 | issue87:python [2015/01/07 15:46] (Version actuelle) – [11] auntiee | ||
|---|---|---|---|
| Ligne 7: | Ligne 7: | ||
| The global ReadyToProcess variable is used to make sure that if the user presses the Process button, the system doesn’t try to process things without anything to process. We use the tkFileDialog askopenfilename built-in dialog routine to get the filename of the original image. We then get the number of colors in the original image as well as the width and height. We save those values and display them in the GUI. We then open the image and create a thumbnail image to display in the left image in the bottom frame. See the text box to the right.** | The global ReadyToProcess variable is used to make sure that if the user presses the Process button, the system doesn’t try to process things without anything to process. We use the tkFileDialog askopenfilename built-in dialog routine to get the filename of the original image. We then get the number of colors in the original image as well as the width and height. We save those values and display them in the GUI. We then open the image and create a thumbnail image to display in the left image in the bottom frame. See the text box to the right.** | ||
| - | Nous avons travaillé | + | Depuis quelques mois, nous travaillons | 
| Nous allons travailler d' | Nous allons travailler d' | ||
| - | La variable globale PretPourTraitement est utilisée pour s' | + | La variable globale PretPourTraitement est utilisée pour s' | 
| ====== 2 ====== | ====== 2 ====== | ||
| Ligne 43: | Ligne 43: | ||
| Nous avons une variable appelée PretPourTraitement (ci-dessous) juste au cas où l' | Nous avons une variable appelée PretPourTraitement (ci-dessous) juste au cas où l' | ||
| - | Nous pixelisons le fichier original à une matrice de pixels 5x5. Cela nous permet de réduire cette matrice | + | Nous pixelisons le fichier original à une matrice de pixels 5x5. Cela nous permet de réduire cette matrice | 
| ====== 4 ====== | ====== 4 ====== | ||
| Ligne 51: | Ligne 51: | ||
| self.im2=Image.open(Reduced) | self.im2=Image.open(Reduced) | ||
| - | self.im2.thumbnail((400, | + | < | 
| self.img3 = ImageTk.PhotoImage(self.im2) | self.img3 = ImageTk.PhotoImage(self.im2) | ||
| Ligne 63: | Ligne 63: | ||
| self.im2=Image.open(Reduite) | self.im2=Image.open(Reduite) | ||
| - | self.im2.thumbnail((500, | + | < | 
| self.img3 = ImageTk.PhotoImage(self.im2) | self.img3 = ImageTk.PhotoImage(self.im2) | ||
| Ligne 81: | Ligne 81: | ||
| self.im2 = Image.open(' | self.im2 = Image.open(' | ||
| - | self.im2.thumbnail((400, | + | < | 
| self.img3 = ImageTk.PhotoImage(self.im2) | self.img3 = ImageTk.PhotoImage(self.im2) | ||
| Ligne 91: | Ligne 91: | ||
| self.GridImage = ' | self.GridImage = ' | ||
| - | Le code ci-dessus met l' | + | Le code ci-dessus met l' | 
| self.DessinerLignes(Reduite, | self.DessinerLignes(Reduite, | ||
| Ligne 99: | Ligne 99: | ||
| self.im2 = Image.open(' | self.im2 = Image.open(' | ||
| - | self.im2.thumbnail((500, | + | < | 
| self.img3 = ImageTk.PhotoImage(self.im2) | self.img3 = ImageTk.PhotoImage(self.im2) | ||
| Ligne 155: | Ligne 155: | ||
| return self.colors** | return self.colors** | ||
| - | La fonction RecupererNbCouleurs utilise la méthode .getcolors pour obtenir le nombre de couleurs dans le fichier image. Nous devons utiliser 1600000 comme paramètre maxcolors parce que si l' | + | La fonction RecupererNbCouleurs utilise la méthode .getcolors pour obtenir le nombre de couleurs dans le fichier image. Nous devons utiliser 1600000 comme paramètre maxcolors parce que, si l' | 
| def RecupererNbCouleurs(self, | def RecupererNbCouleurs(self, | ||
| Ligne 176: | Ligne 176: | ||
| return im.size[0], | return im.size[0], | ||
| + | Les deux fonctions suivantes renvoient la hauteur et la largeur en pixels du fichier image. La différence entre les deux est que RecupererHauteurLargeur renvoie une chaîne comme 1024x768 et RecupererHauteurLargeur2 renvoie deux nombres entiers. | ||
| + | |||
| + | def RecupererHauteurLargeur(self, | ||
| + | im = Image.open(fichier) | ||
| + | tmp = " | ||
| + | return tmp | ||
| + | |||
| + | def RecupererHauteurLargeur2(self, | ||
| + | im = Image.open(fichier) | ||
| + | return im.size[0], | ||
| + | |||
| ====== 9 ====== | ====== 9 ====== | ||
| Ligne 185: | Ligne 196: | ||
| The Pixelate function (above) takes two parameters, image filename (im) and the size of pixels you want. The work is done by the image.resize method. I found this routine on the web in a number of places. In this instance we will be passing a pixel size of 5, which works well for Cross Stitch projects. We also tell the method to take the color of the nearest neighbor. This returns a new image, which we save as a file and return the filename.** | The Pixelate function (above) takes two parameters, image filename (im) and the size of pixels you want. The work is done by the image.resize method. I found this routine on the web in a number of places. In this instance we will be passing a pixel size of 5, which works well for Cross Stitch projects. We also tell the method to take the color of the nearest neighbor. This returns a new image, which we save as a file and return the filename.** | ||
| + | |||
| + | RecupererCouleurs cherchera le nombre de couleurs dans l' | ||
| + | |||
| + | def RecupererCouleurs(self, | ||
| + | nbCouleurs = image.getcolors(1600000) | ||
| + | couleurs = len(nbCouleurs) | ||
| + | |||
| + | La fonction Pixeliser (ci-dessus) prend deux paramètres, | ||
| ====== 10 ====== | ====== 10 ====== | ||
| Ligne 198: | Ligne 217: | ||
| The ScrollList (below) on the right side holds the colors that will be used to get the proper floss colors. We simply create labels to hold the colors (visual) and text.** | The ScrollList (below) on the right side holds the colors that will be used to get the proper floss colors. We simply create labels to hold the colors (visual) and text.** | ||
| + | |||
| + | La routine ReduireCouleurs (ci-dessous) utilise essentiellement la palette Image.ADAPTIVE afin d' | ||
| + | |||
| + | Il y a deux routines DessinerLignes (en haut à droite). Elles créent la grille dont nous avons parlé plus tôt. | ||
| + | |||
| + | Rgb2Hex() retourne une valeur hexadécimale de la valeur RVB qui est passée. Nous allons l' | ||
| + | |||
| + | def Rgb2Hex(self, | ||
| + | return '# | ||
| + | |||
| + | La liste déroulante (ci-dessous) sur le côté droit contient les couleurs qui seront utilisées pour obtenir les couleurs appropriées de fils. Nous créons simplement des « labels » pour contenir les couleurs (visuelles) et le texte. | ||
| ====== 11 ====== | ====== 11 ====== | ||
| Ligne 207: | Ligne 237: | ||
| As always, the code is available on PasteBin at http:// | As always, the code is available on PasteBin at http:// | ||
| + | Voici la routine (page suivante) que nous utilisons pour essayer de trouver la meilleure correspondance entre la couleur dans l' | ||
| + | |||
| + | Bon. C'est tout pour ce mois-ci. La prochaine fois, nous allons commencer à créer le fichier de sortie PDF pour que la brodeuse ait un support avec lequel travailler. | ||
| - | VF : http:// | + | Comme toujours, le code est disponible sur Pastebin | 
| ====== cadres orangés ====== | ====== cadres orangés ====== | ||
issue87/python.1420491416.txt.gz · Dernière modification : 2015/01/05 21:56 de fredphil91
                
                