Popular recipes tagged "pil" but not "images"http://code.activestate.com/recipes/tags/pil-images/2017-04-10T21:14:36-07:00ActiveState Code RecipesMetro Spinner for Tkinter (Python) 2017-04-10T21:14:36-07:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580777-metro-spinner-for-tkinter/ <p style="color: grey"> Python recipe 580777 by <a href="/recipes/users/4189907/">Miguel Martínez López</a> (<a href="/recipes/tags/canvas/">canvas</a>, <a href="/recipes/tags/image/">image</a>, <a href="/recipes/tags/pil/">pil</a>, <a href="/recipes/tags/rotation/">rotation</a>, <a href="/recipes/tags/spinner/">spinner</a>, <a href="/recipes/tags/tkinter/">tkinter</a>). </p> <p>I create a rotating image class <em>RotatingIcon</em> inspired and based on this code:</p> <p><a href="http://stackoverflow.com/questions/15736530/python-tkinter-rotate-image-animation" rel="nofollow">http://stackoverflow.com/questions/15736530/python-tkinter-rotate-image-animation</a></p> <p>Features:</p> <ul> <li>Methods to stop and start the animation</li> <li>The animation automically stops when the window is not mapped, and the animation continues when the window is mapped again</li> <li>Time setting to control the speed of the animation</li> <li>All the formats accepted for PIL could be used. XBM format is automatically converted to Tk Bitmap. The advantage of Bitmats is the possibility to change the color of the foreground.</li> </ul> <p>I added 6 different styles of spinners with different sizes.</p> <p>I used fontawesome.io for the icon generation.</p> <p>For more metro widgets see here:</p> <p><a href="https://code.activestate.com/recipes/580729-metro-ui-tkinter/" rel="nofollow">https://code.activestate.com/recipes/580729-metro-ui-tkinter/</a></p> Dynamical Billiards Simulation (Python) 2013-06-20T06:57:57-07:00Steve Wadleyhttp://code.activestate.com/recipes/users/4186942/http://code.activestate.com/recipes/578572-dynamical-billiards-simulation/ <p style="color: grey"> Python recipe 578572 by <a href="/recipes/users/4186942/">Steve Wadley</a> (<a href="/recipes/tags/chaos/">chaos</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/pil/">pil</a>, <a href="/recipes/tags/random/">random</a>). </p> <p>It simulates reflections of a ball on a billiards table that has one or more circular obstacles. (This can also be thought as a 2d ray-tracing.)</p> <p>Most of the time the path of the ball would be chaotic (meaning, if another ball started from any slightly different location or direction then its path would be very different after a short while). </p> <p>See Wikipedia for more info: <a href="http://en.wikipedia.org/wiki/Dynamical_billiards" rel="nofollow">http://en.wikipedia.org/wiki/Dynamical_billiards</a></p> Bilinear Interpolation (Python) 2013-02-23T04:00:52-08:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/578469-bilinear-interpolation/ <p style="color: grey"> Python recipe 578469 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/image/">image</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/pil/">pil</a>). </p> <p>Creates a surface from a grid of random numbers using Bilinear Interpolation.</p> True-color Mandelbrot Fractal (Python) 2013-01-14T02:07:47-08:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/578415-true-color-mandelbrot-fractal/ <p style="color: grey"> Python recipe 578415 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/pil/">pil</a>). Revision 2. </p> <p>True-color Mandelbrot Fractal. It uses |x|, |y|, |z|, |angle(z)| values of the final iteration point for coloring.</p> Random Maze Generator (Python) 2012-12-14T09:09:22-08:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/578356-random-maze-generator/ <p style="color: grey"> Python recipe 578356 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/ai/">ai</a>, <a href="/recipes/tags/game/">game</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/pil/">pil</a>). Revision 2. </p> <p>Random maze generator using depth-first search.</p> <p>It starts the maze path from a random cell and there is no exit defined but actually any 2 cells on the path (white cells) can be assigned to be entry and exit locations. (I could just add code to randomly select 2 white cells and change their colors to something else but I thought it looks better this way.)</p> Random Multi-Maze Generator (Python) 2012-12-14T11:23:29-08:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/578378-random-multi-maze-generator/ <p style="color: grey"> Python recipe 578378 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/ai/">ai</a>, <a href="/recipes/tags/game/">game</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/pil/">pil</a>). </p> <p>Randomly creates mazes which have multiple paths to solve. Entry and exit points for each path can be assigned arbitrarily. (I never seen this kind of maze anywhere before but I think calling them multi-maze should be okay.)</p> Knight's Tour Map using Warnsdorff's Algorithm (Python) 2012-12-18T01:05:51-08:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/578386-knights-tour-map-using-warnsdorffs-algorithm/ <p style="color: grey"> Python recipe 578386 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/algorithm/">algorithm</a>, <a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/pil/">pil</a>). </p> <p>Solves Knight's Tour Problem using Warnsdorff's Algorithm for every square on the chessboard of arbitrary size.</p> <p>It colors each initial square with a color that depends on the final square coordinates. (This is a method used to create fractals.) Many different formulas maybe used for coloring (based on abs/rel x/y/dist/ang).</p> <p>Calculating each tour in full creates a highly chaotic image (and takes hours). So I added maxItPercent to cut-off tours earlier. (Using %10 creates an image that has both ordered and chaotic regions.)</p> EXIF-date-based JPEG files rename using PIL (Python) 2012-07-21T02:38:33-07:00Jorge Barnabyhttp://code.activestate.com/recipes/users/4182918/http://code.activestate.com/recipes/578219-exif-date-based-jpeg-files-rename-using-pil/ <p style="color: grey"> Python recipe 578219 by <a href="/recipes/users/4182918/">Jorge Barnaby</a> (<a href="/recipes/tags/date/">date</a>, <a href="/recipes/tags/exif/">exif</a>, <a href="/recipes/tags/jfif/">jfif</a>, <a href="/recipes/tags/jpeg/">jpeg</a>, <a href="/recipes/tags/jpg/">jpg</a>, <a href="/recipes/tags/photo/">photo</a>, <a href="/recipes/tags/pil/">pil</a>, <a href="/recipes/tags/rename/">rename</a>). Revision 2. </p> <p>Rename JPEG files according to EXIF-date using PIL [library].</p> <p>If global variable CREATE_HARDLINK is set, script creates Windows (XP) batch file for creating hardlink version of source files.</p> <p>PIL available here: <a href="http://www.pythonware.com/products/pil/" rel="nofollow">http://www.pythonware.com/products/pil/</a></p> Conversion of PIL Image and numpy array (Python) 2011-03-05T03:47:56-08:00Shao-chuan Wanghttp://code.activestate.com/recipes/users/4168519/http://code.activestate.com/recipes/577591-conversion-of-pil-image-and-numpy-array/ <p style="color: grey"> Python recipe 577591 by <a href="/recipes/users/4168519/">Shao-chuan Wang</a> (<a href="/recipes/tags/numpy/">numpy</a>, <a href="/recipes/tags/pil/">pil</a>). Revision 2. </p> <p>The utility function that converts PIL image to numpy array and vice versa.</p> Dynamical Billiards Simulation (Python) 2010-10-30T06:22:28-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577445-dynamical-billiards-simulation/ <p style="color: grey"> Python recipe 577445 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/chaos/">chaos</a>, <a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/pil/">pil</a>, <a href="/recipes/tags/random/">random</a>). </p> <p>It simulates reflections of a ball on a billiards table that has one or more circular obstacles. (This can also be thought as a 2d ray-tracing.)</p> <p>Most of the time the path of the ball would be chaotic (meaning, if another ball started from any slightly different location or direction then its path would be very different after a short while). </p> <p>See Wikipedia for more info: <a href="http://en.wikipedia.org/wiki/Dynamical_billiards" rel="nofollow">http://en.wikipedia.org/wiki/Dynamical_billiards</a></p> 4D Mandelbrot Fractal (Python) 2012-07-07T23:42:43-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577715-4d-mandelbrot-fractal/ <p style="color: grey"> Python recipe 577715 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/pil/">pil</a>). Revision 4. </p> <p>Draws a random 2D slice from 4D Mandelbrot fractal.</p> Gumowski-Mira Strange Attractor (Python) 2010-12-07T09:54:51-08:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577486-gumowski-mira-strange-attractor/ <p style="color: grey"> Python recipe 577486 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/chaos/">chaos</a>, <a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/pil/">pil</a>). Revision 4. </p> <p>It draws a random Gumowski-Mira Strange Attractor. (It would retry until a good one is found to display.)</p> Write a PNG image in native Python (Python) 2010-10-28T12:03:52-07:00Campbell Bartonhttp://code.activestate.com/recipes/users/4168177/http://code.activestate.com/recipes/577443-write-a-png-image-in-native-python/ <p style="color: grey"> Python recipe 577443 by <a href="/recipes/users/4168177/">Campbell Barton</a> (<a href="/recipes/tags/alpha/">alpha</a>, <a href="/recipes/tags/image/">image</a>, <a href="/recipes/tags/pil/">pil</a>, <a href="/recipes/tags/png/">png</a>, <a href="/recipes/tags/save/">save</a>). </p> <p>This is a simple PNG writing function, intended to be as small as possible. It only supports RGBA 32bit PNGs and the input should be a buffer of rgba bytes.</p> <p>Tested for python 2 and 3.</p> Dynamical Billiards Simulation Map (Python) 2010-11-07T18:21:06-08:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577455-dynamical-billiards-simulation-map/ <p style="color: grey"> Python recipe 577455 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/chaos/">chaos</a>, <a href="/recipes/tags/fractal/">fractal</a>, <a href="/recipes/tags/image/">image</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/pil/">pil</a>). Revision 4. </p> <p>It creates fractal-like map plots from the simulation.</p> <p>(See my other post titled "Dynamical Billiards Simulation" first!)</p> <p>I had to keep image size and maxSteps small otherwise the calculation takes too long!</p> <p>(It shows what percentage of calculations completed every 10 seconds also.)</p> Planet Terrain Heightmap Generator (Python) 2010-03-10T16:35:37-08:00Shea Kauffmanhttp://code.activestate.com/recipes/users/4168682/http://code.activestate.com/recipes/576929-planet-terrain-heightmap-generator/ <p style="color: grey"> Python recipe 576929 by <a href="/recipes/users/4168682/">Shea Kauffman</a> (<a href="/recipes/tags/creation/">creation</a>, <a href="/recipes/tags/generation/">generation</a>, <a href="/recipes/tags/generator/">generator</a>, <a href="/recipes/tags/heightmap/">heightmap</a>, <a href="/recipes/tags/landscape/">landscape</a>, <a href="/recipes/tags/map/">map</a>, <a href="/recipes/tags/pil/">pil</a>, <a href="/recipes/tags/planet/">planet</a>, <a href="/recipes/tags/planted/">planted</a>, <a href="/recipes/tags/pygame/">pygame</a>, <a href="/recipes/tags/terrain/">terrain</a>, <a href="/recipes/tags/world/">world</a>). Revision 9. </p> <p>The process is simply: 1. Take a plane 2. Cut out a shape 3. Make it a little taller 4. Repeat</p> <ul> <li>Similar to the <a href="http://freespace.virgin.net/hugo.elias/models/m_landsp.htm">spherical landscape</a> algorithm by Hugo Elias.</li> <li>I found a combination of Ovals and Triangles to produce the best results.</li> </ul> Putting watermark to images in batch (Python) 2009-06-20T18:05:08-07:00hasanatkazmihttp://code.activestate.com/recipes/users/4168973/http://code.activestate.com/recipes/576818-putting-watermark-to-images-in-batch/ <p style="color: grey"> Python recipe 576818 by <a href="/recipes/users/4168973/">hasanatkazmi</a> (<a href="/recipes/tags/batch/">batch</a>, <a href="/recipes/tags/image_processing/">image_processing</a>, <a href="/recipes/tags/pil/">pil</a>, <a href="/recipes/tags/watermark/">watermark</a>). </p> <p>Being a novice photographer, I usually have many pictures - sometimes in hundreds. While posting on Flickr or other online sources, it is very important to put watermark on all of them, like signature or email. This is a small self explanatory snippet which will place watermark image on right bottom corner. You just provide source folder and it will scan all photos in that folder (not sub folders) and will produce watermarked photos in the destination folder. It worked for me with jpg, it should work for all those formats which PIL can work with.</p> EXIF-date-based JPEG files rename using PIL (Python) 2009-02-10T07:28:48-08:00Denis Barmenkovhttp://code.activestate.com/recipes/users/57155/http://code.activestate.com/recipes/576646-exif-date-based-jpeg-files-rename-using-pil/ <p style="color: grey"> Python recipe 576646 by <a href="/recipes/users/57155/">Denis Barmenkov</a> (<a href="/recipes/tags/date/">date</a>, <a href="/recipes/tags/exif/">exif</a>, <a href="/recipes/tags/jfif/">jfif</a>, <a href="/recipes/tags/jpeg/">jpeg</a>, <a href="/recipes/tags/jpg/">jpg</a>, <a href="/recipes/tags/photo/">photo</a>, <a href="/recipes/tags/pil/">pil</a>, <a href="/recipes/tags/rename/">rename</a>). Revision 4. </p> <p>Rename JPEG files according to EXIF-date using PIL [library].</p> <p>If global variable CREATE_HARDLINK is set, script creates Windows (XP) batch file for creating hardlink version of source files.</p> <p>PIL available here: <a href="http://www.pythonware.com/products/pil/" rel="nofollow">http://www.pythonware.com/products/pil/</a></p> Pad images to power-of-two dimensions. (Python) 2008-08-12T18:46:40-07:00Martin Wilsonhttp://code.activestate.com/recipes/users/4166376/http://code.activestate.com/recipes/576416-pad-images-to-power-of-two-dimensions/ <p style="color: grey"> Python recipe 576416 by <a href="/recipes/users/4166376/">Martin Wilson</a> (<a href="/recipes/tags/graphics/">graphics</a>, <a href="/recipes/tags/imaging/">imaging</a>, <a href="/recipes/tags/library/">library</a>, <a href="/recipes/tags/of/">of</a>, <a href="/recipes/tags/opengl/">opengl</a>, <a href="/recipes/tags/pil/">pil</a>, <a href="/recipes/tags/power/">power</a>, <a href="/recipes/tags/power_of_two/">power_of_two</a>, <a href="/recipes/tags/python_imaging_library/">python_imaging_library</a>, <a href="/recipes/tags/two/">two</a>). Revision 4. </p> <p>Pads any amount of images each to power-of-two dimensions, useful for OpenGL programming.</p> JPG files redater by EXIF data (Python) 2014-12-11T10:07:39-08:00Michal Niklashttp://code.activestate.com/recipes/users/186902/http://code.activestate.com/recipes/550811-jpg-files-redater-by-exif-data/ <p style="color: grey"> Python recipe 550811 by <a href="/recipes/users/186902/">Michal Niklas</a> (<a href="/recipes/tags/date/">date</a>, <a href="/recipes/tags/exif/">exif</a>, <a href="/recipes/tags/e_uae/">e_uae</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/jpeg/">jpeg</a>, <a href="/recipes/tags/jpg/">jpg</a>, <a href="/recipes/tags/pil/">pil</a>). Revision 6. </p> <p>Iterates through a directory, reading the EXIF data from each jpg/jpeg file. Parses the date/time from EXIF data and:</p> <ol> <li>if it differs from file modification date/time then changes file date/time</li> <li>moves file to <code>YYYY/YYYY_MM_DD</code> directory</li> </ol>