Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Thursday, January 23, 2025

Do you know how to create a GIF?

   You have seen a GIF image and enjoyed it. But have you created one.? There are software programs to create GIFs and perhaps many online sites help creating GIFs.  Here is one for example, https://www.canva.com/create/gif-maker/. Animation akin to GIFS can also be created using javascript although there may not be resulting image with a .gif extension.

GIFs are like very small duration video clips but they are really a composite of many small images flipped rapidly, in-situ to create the illusion of motion. They are made to impress you by their motion.

Why GIFS?

Imagine bringing life to a still photo of a sunset by animating the clouds. An image may be worth a thousand words, but a GIF is worth a thousand images. It adds dynamic movement to static images, unleashing your creativity. If you're active on social media, GIFs are an invaluable tool for self-expression, offering endless possibilities. They bring humor, emotion, and laughter to any page, transforming a collection of static images into a vibrant and engaging experience. With GIFs, you can elevate your storytelling to new heights!"

Here is a simple GIF image copied from a web site  (display gif on web browser - Search):


Ins and outs of using Python to create GIFs:

GIF images have the .gif extension which stands for Graphics Interchange Format. 

In this post, I show you how to create from scratch a GIF using Python. Python uses a image library such as PIL to get the images into the program such as PyCharm. Once they are in the program, you need to use another library to do the flipping action. This library is called imageio, image input/output program. For GIFs this program takes in the images (a number of them) and then it customizes the duration each image is shown; whether the gif repeats itself and how many times it does, etc. Note: if you are new to PyCharm, read up my other Python/Image related posts in this blog, http://hodentekhelp.blogpost.com.

The program presented here also goes through the indexing of the images (as there are many images) which necessitate calling yet another useful library called NumPy. The imageio program cannot accept a image list, but a Numpy list and hence the use of the NumPy library.

In order to create a gif file in a python program, you need the following:

1. A set of images. 

2. Importing libraries PIL, ImageIO and Numpy.

Here is are some five image files I am using in the program:






These are not the best, but enough for the purpose.

Here is the python program that creates a GIF image taking in the images shown here:

----------------------------

BirdsGIF.py

-----------------

# Import libraries used to create a GIF image

import imageio

import numpy as np

from PIL import Image

from PIL.ImageFile import ImageFile

# Load images

image1: ImageFile = Image.open(r'C:\Users\hoden\PycharmProjects\exploreImage\Images_3\Bird1.jpg')

image2 = Image.open(r'C:\Users\hoden\PycharmProjects\exploreImage\Images_3\Bird2.jpg')

image3 = Image.open(r'C:\Users\hoden\PycharmProjects\exploreImage\Images_3\Bird3.jpg')

image4 = Image.open(r'C:\Users\hoden\PycharmProjects\exploreImage\Images_3\Bird4.jpg')

image5 = Image.open(r'C:\Users\hoden\PycharmProjects\exploreImage\Images_3\Bird5.jpg')

# Resize images (optional)

image1 = image1.resize((200, 200))

image2 = image2.resize((200, 200))

image3 = image3.resize((200,200))

image4 = image4.resize((200,200))

image5 = image5.resize((200,200))

# Create list of images

images = [image1, image2, image3, image4, image5]

# Convert PIL image  list to NumPy arrays

images = [np.array(img) for img in images]

# Create the GIF using the image list

imageio.mimsave('my_animation.gif', images, duration=2000.0, loop=5)

----------------------

The above program creates a image file with .gif extension and images show for 2000 milliseconds and the GIF image runs five times in succession. If you have time elapsed stills of any event you can easily turn it into an amazingly dynamic image.

That is all there is to creating a GIF. If your images are made with care and are of good quality you can indeed create a good GIF.

The GIf file created, my_animation.gif can be seen in Photo app on your windows computer device, however you can just drag and drop the image on a browser should also work.


Mahalo for staying with me. 

p.s: For these holidays, you can create your greeting card with a GIF. Try it!





Thursday, August 19, 2021

Client using Python to access data on AWS S3

Python is one of the most trending programming languages and it can use the web framework to create database projects. The client using an intermediary flask server is well suited. 

You can develop a client application using React with Python and access the AWS's S3 bucket via  Flask server.

Here are some relevant links that you may want to look up or quick tutorials to get the hang of it.


How to create a React+Flask Project?

https://blog.miguelgrinberg.com/post/how-to-create-a-react--flask-project

https://rajrajhans.com/2020/06/2-ways-to-upload-files-to-s3-in-flask/


Microsoft Visual Studio provides full support for almost any kind of project:


https://code.visualstudio.com/docs/python/tutorial-flask


https://code.visualstudio.com/docs/nodejs/reactjs-tutorial


https://aws.amazon.com/about-aws/whats-new/2020/07/amazon-s3-features-now-available-aws-toolkits-for-visual-studio-code/

You can get a link to download the latest community version(free) here:

https://hodentek.blogspot.com/2021/07/visual-studio-2022-preview-available.html

Friday, June 19, 2020

Why should you learn Python?

There is great value in learning Python.

You may want to read this link to learn the use cases of Python.

Insurance: creating business insights with machine learning
Retail banking: flexible data transformation and manipulation
Aerospace: meeting software system deadlines
Finance: data mining to identity cross-sell opportunities
Business services: API access to financial information
Hardware: automating network administration
Healthcare: predicting disease prognosis
Consulting services: bespoke web development
InfoTech: IT modernization
Software: adding extensibility to legacy applications

Source:
https://www.activestate.com/resources/datasheets/top-10-python-use-cases/


Python is also used for backend in Web Applications where it is used for scripting
2) Desktop GUI Applications.
3) Software Development. ...
4) Scientific and Numeric. ...
5) Business Applications. ...
6) Console Based Application. ...
7) Audio or Video-based Applications. ...
8) 3D CAD Applications.

For more applications read here:
https://intersog.com/blog/python-application-development-common-use-cases-and-project-examples/

Read all Python-related posts in this blog:
https://hodentekhelp.blogspot.com/search?q=python

Sunday, September 30, 2018

Get going with SPSS

Data Science is trending. What with Machine Learning and Artificial Intelligence, learning to work with statistical analysis tools will take you far.

Here is an IBM one liner for SPSS:

"Propel research & analysis with a fast and powerful solution"

SPSS is an acronym for Statistical Software for Social Sciences. Its beginnings dates back to 1968 and it was acquired by IBM in 2009. Files created by this software have the extension .sav. SPSS outputs tables and charts that can processed by MS Word, Google Docs, Open Office, etc.

SPSS can be used for editing and analyzing data similar to other software such as R, Excel, Python, etc.

Here is a PR demo from IBM




More SPSS stuff here:



You could get a copy for free for a short term.

You could the free version for 14 days. The free version also has the following Add-ons.

Custom Tables & Advanced Statistics Users
Custom Tables and Advanced Statistics Add-on provides easy to use drag and drop interactive tables exportable to Microsoft/PDF. You can access a variety of additional techniques such as; Non-linear, logistic, 2-stage least squares regression, Generalized linear modeling and survival analysis. Additionally, Bayesian Statistics now available.
Complex Sampling & Testing Users
Complex Sampling and Testing Add-on provides functionality for small sample sizes, missing data , and complex sampling. You can access regression with optimal scaling including lasso and elastic net. Additional features include; categorical principal components analysis, multidimensional scaling and unfolding, and multiple correspondence analysis.
Forecasting & Decision Trees Users
Forecasting and Decision Trees Add-on provides ARIMA and exponential smoothing forecasting capabilities. Classification and decision trees based on four established tree-growing algorithms are also available. You can also create neural network predictive models as well as RFM analysis to test marketing campaigns.

Each of the add-ons costs $79.00

Go to this link and fill out the form for free download:


Thursday, August 09, 2018

Probably the best language to learn now is Python


Of course, you want the most popular and the most valuable.

According to the Institute of Electrical and Electronics Engineers (IEEE) , it is Python, the clear winner.

Here are the top ten in its rankings:


Why Python?

The answer appears to the fact that it iss now used for embedded applications and because it has beefed up its repertoire related to AI and Machine learning. It is for this reason R language (somewhat speccialized) has seen some decline.

Microsoft C# is still handing there at 5 and probably its place will be solid 5 for all types of programming - Web, desktop and Mobile. SQL is also there but does not show up as top 10 which is understandable given its area of usage.

Well here is the first 20. Find if your favorite is here



Well, you may want to know the basis for the ranking. You can get to know here.

You can find a lot of posts on R and Python on this site.



You can find a lot of Python and R posts in my blogs.

Sunday, July 22, 2018

IronPython: Python programming for .NET Framework

Python is the object oriented, Open source programming language that has become very popular because of a large support group as well as best suited for AI and Machine learning. Some say it is even more powerful than Matlab (numerical computing environment and programming).

.NET Framework is Microsoft's code foundation with Common Language Runtime and a huge class library that connects all Microsoft products.

If there is something that works with both with .NET leveraging Python and Python leveraging Python then one can have the best of both.

Well, IronPython is supposed to embody this important role. This is what on finds on IronPython site

"IronPython is an open-source implementation of the Python programming language which is tightly integrated with the .NET Framework. IronPython can use the .NET Framework and Python libraries, and other .NET languages can use Python code just as easily"

You can download IronPython 2.7.x from here.

IronPython is dubbed the Python programming for the .NET Framework.

Thursday, June 07, 2018

Connecting to SQL Server 2016 using Python

pyodbc is an open source Python module that simplifies accessing ODBC databases. It implements the DB API 2.0 specs and has been filled with Python related items.

Connecting to SQL Server (SQL Server 2016 Sp2) is easy as long as you get the needed items correctly.

Review the following link if you landed on this page:

Read here installing pyodbc on your Windows 10 computer:
http://hodentekhelp.blogspot.com/2018/06/how-do-you-install-pyodbc.html

Read here connecting to SQL Server using pyodbc
http://hodentekhelp.blogspot.com/2018/06/how-do-you-connect-to-sql-server-using.html

Sunday, April 01, 2018

Accessing array items in Python is easy using indexing

Looks like a trick question.

There is no Array in Python but an object List exists which can be used to the same end.
  • The List may contain different list items or same kind of list items.
  • The List is indexed and zero based. The first list item has an index 0.
  • You can retrieve list items using their index. Even negative index is OK.
As defined here lst is a list .

lst=["a", "b", "c", "e"]

The list can have strings like this as well:

lst2=['a', 'b', 'c', 'e']

They both evaluate to the same: ['a', 'b', 'c', 'e']


List may contain different types of List Items as in this definition.


 lst2=["ab", 8, True, 5.8]

Retrieving list items using index
>>> lst[0]
'a'
>>> lst[-1]
'e'
>>> lst2[-2]
True
>>> lst[5]
Traceback (most recent call last):
  File "", line 1, in
IndexError: list index out of range

Negative Index
>>> lst[-1]
'e'
>>> lst2[-2]
True


These evaluations were carried out using Python 3.6.2



Tuesday, March 20, 2018

Python support in Visual Studio Community 2017

Yes, in a big way. Just the Intellisense support may by itself a great help.

You need to install PTVS (Python Tools for Visual Studio) to have Python support in Visual Studio (2017,2015, 2013 and earlier). In Visual Studio 2015 you need a Python Interpreter (Python 3.5 or earlier, 3.6 and above are not supported). The VS may guide you to install a Python Interpreter.

Python support is not presently available in Visual Studio for Mac, but is available on Mac and Linux through Visual Studio Code.

More here:

Well, here is my personal take. I have Microsoft Visual Studio Community 2017, version 15.5.7 which has the following Python related products:

VS2017Python_1

In the installed templates I can see all of the following that are specific to Python:


VS2017Python_0
What is more. You also get other perks, if you install Visual Studio that I have installed:


VS2017Python_2

Actually, I have other Python stuff as well:










Saturday, March 10, 2018

Launching Python from Command-line


Python installed using the pyton-3.7.0b2-webinstall installs python to the following directory on your computer:

C:\Users\Owner\AppData\Local\Programs\Python\Python37-32\

However if you want to run python (python3.7(32bit)) you can either go the above directory and launch or by double-clicking the shortcut on All programs.

However if you wish to launch python from the C:\>  prompt, you should add the above folder to the PATH environment variable.


Enter environmental variables in the search charm.


Click to open the System Properties as shown.




Click Environmental Variables...


Highlight Path in the top pane and click Edit...


Click New and add the installed directory as shown.

Now you can lunch python from the C:>/ prompt as shown.






DMCA.com Protection Status