[Addon] Image Resizer (requires pil!)

erdinc, I have one squestion: sudo pip -U install pillow

What is the option -U please, I don’t find?

It is short version of the “–upgrade” option.
if you already have a package installed, it will upgrade the package for you. Without the -U option it’ll tell you the package is already installed and exit.
Actually it is not necesarry. But i think it has become a convention or something i see it everywhere.

I am glad it worked :slight_smile: I hope it would be useful for your workflow.

Why your script or Blender don’t use PIL normally???

Because of PYTHONPATH environment variable. Every python installation has its own PYTHONPATH.
PYTHONPATH sets the search paths for importing python modules. It is a colleciton of paths. We can add to blender’s pythonpath system’s dist-packages directory path if we want. And it would work. But these dist-package paths are not consistent across distros and operating systems. So there is no easy way to add all possible paths to the script. But i ll try to add an addon option to the preferences for selecting PIL module path.

to see the list of paths that python searches for installed modules:

import sys
sys.path

to add some path to the list:

import sys
sys.path.append("/some/module/path")

Ho Ok Thks for the explanation, I understand very well now. here is the answer fo Blender:


>>> import sys
>>> sys.path
['/usr/share/blender/2.77/scripts/addons_contrib',
'/home/patrinux/.config/blender/2.77/scripts/addons',
'/usr/share/blender/2.77/scripts/addons',
'/home/patrinux/.config/blender/2.77/scripts/modules',
'/usr/share/blender/2.77/scripts/startup',
'/usr/share/blender/2.77/scripts/modules',
'/usr/lib/python3.5',
'/usr/lib/python3.5/plat-x86_64-linux-gnu',
'/usr/lib/python3.5/lib-dynload',
'/usr/local/lib/python3.5/dist-packages',
'/usr/lib/python3/dist-packages',
'/usr/share/blender/2.77/scripts/freestyle/modules',
'/usr/share/blender/2.77/scripts/addons/modules',
'/home/patrinux/.config/blender/2.77/scripts/addons/modules',
'/home/patrinux/.config/blender/2.77/scripts/addons/add_window/../add_window',
 '/home/patrinux/.config/blender/2.77/scripts/addons/prokitektura']

is it good or I must add a path, please? No i mean: ‘/home/patrinux/.config/blender/2.77/scripts/modules’, is ok for new module.

BUT
I see that ‘/usr/local/lib/python3.5/dist-packages’ exist but the folder is empty!!!
Now I have found the dist-package for python3.5, how to python3.5 compile pillow to this folder, please?

I tried to uninstall pillow and re-install again but the answer was “pillow is installed by the system so pillow for python3 can’t to be uninstalled!” ???

Badly when I use the command “sudo pip -U install pillow” I havn’t create a log file of the installation.

Let’s try an alternative way. But you need to be carefull.

First go to your blender installation directory and find python
/your-blender-dir/2.77/python/bin/python3.5m (or it may be python3.5)

Download and save the “get-pip.py” to this directory also.

Open a terminal and cd to same directory and execute the script.

cd /your-blender-dir/2.77/python/bin/
./python3.5m get-pip.py

This will hopefully install pip to blender’s python.
If this is succesful, install pillow with this command.

./pip install -U pillow

This will install pillow directly to the blender’s python.

After that, If you want you can delete the “get-pip.py”

BUT “/your-blender-dir/2.77/python/bin/python3.5m” ???
My Blender is installed with ppa directly in my OS!
In my usr/share/Blender I havn’t this file.

Dans mon HOME/.config/blender/2.77/ , je n’ai pas de dossier python!

In my linux Mint 17.3 system, I have this;
python3.5m” Do you want to say this? : LINK

Ok, I see. Your blender already uses your system’s python3.5. (further information)
If you could install pillow to your system python3.5 it would directly see it, we would not need extra steps.

So, I installed a mint distro for further investigation.
Mint’s pillow package(named python3-pil) does not support python3.5 ("Depends: python3(<3.5) ")
We can not install pillow for python3.5 with package manager in mint. (for now)

Here, how i solved the issue in my testing mint installation.

First i installed python3.5

sudo apt-get install python3.5 python3.5-dev

Than i installed pillow dependencies

sudo apt-get install libtiff4-dev libjpeg8-dev zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.6-dev tk8.6-dev

installed virtualenv

sudo apt-get install python-virtualenv

created a python3 virtual environment


cd ~
virtualenv -p /usr/bin/python3.5 myPilEnv

#switch to newly created environment
source myPilEnv/bin/activate

# now you should see on the command line <b>(myPilEnv)</b><i>aaa@asasd </i>~ $:
# that means we are in our virtual environment. 
# when we use pip in here, it will install the module to our virtual environment

# install pillow (no need to sudo)
pip install -U pillow

# hopefully it will be succesfully installed.

#and finally deactivate myPilEnv virtual environment
deactivate

now copy or (symlink) PIL directory from

~/myPilEnv/lib64/python3.5/site-packages/PIL 

to

/home/patrinux/.config/blender/2.77/scripts/modules

and hopefully it will work.

Finally, you can delete ~/myPilEnv directory if you want.

You are a big Chief, Dear Erdinc, It work very well now
I must studied that you have made because i don’t know but it’s a great method!
I love python but sometimes it’s very difficult to manipulate it between version and different system.

>>>Finally, you can delete ~/myPilEnv directory if you want.
I kept it naming .myPilEnv in invisible folder, we never know.

Now I must studied your addon with the video…CONGRATULATIONS !

EDIT: Ok I understand now:
you use (myPilEnv) to change of terminal operation in virtual mode that you have created to use pip to install some modules you wanted. And then i copy this modules in my blender module as I asked you after.
Then you get out of this virtual environment, and you normally run Blender.

Top-notch method! Thanks a lot.

YOUR ADDON :
is very useful!
I understood all parameters but not the main 2k or 1k! Is it the size limit in 2 000 Mo or the resolution in px/inch.
Because you have the size in pixel then?

If I have a texture 2350 x 864 for example, how to just x2 the size in 4700 x 1728, please? I must calculate myself the dimension and change the size in cells?

EDIT YET: I have understood: the first parameter is a memorization of your setups of size: Very useful!
very easy.

but the “keep aspect” must be automatic with the original size of the texture and the choice of the result size. If coeficient of scale width and coeficiant of height are different, the box could be visible and value = False, if you choose True in that kind: the function calculate the size automatiquely to keep ratio, not?

I am glad it worked :slight_smile: I hope you find the addon useful.
And thanks to you Dear Spirou4D. Now i can make an extensive 3rd party python module install guide for blender :slight_smile: I am working on it now.

And yes exactly you get the idea.
Also some extra notes about virtualenv:
With virtualenv, we created an isolated python environment and used its own pip to install pillow. A virtual environment has its own dist-packages directory and own python + pip executables. So it installed the pillow to its own dist-packages(or site-packages) directory. And we copied from there.
You can create many of them with different python versions side by side. And they won’t effect or conflict with each other or system’s python. (More info about virtualenv)

Happy bl.

Ho I am glad to know you Erdinc, your job is very good!

Thanks you so much fot your explanations about virtualenv and THE link! :eyebrowlift:

Recently I have made these addons: Artist Paint Tools (panel and popup menu) here: LINK
with Craig Jones here are some vodeo s to explain: LINK link2

and others on my github. Have fun to use it…

I am glad to know you too :slight_smile: Thanks Spirou4D.
I looked your addon and it looks very useful. I will definetely use it . Nice work !!

Happy you like it.
There are a lot of options and setup, send me questions, i will explain you the secrets.
This addon run only with BI, I must rewrite it to Cycles but it’s a big job…

I hope Blender Foundation don’t remove BI for Blender 2.78…:cool:

PS: When you create a layer, the curve is copied in layer 20 invisible so you can at any moment reuse it to a new layer.