# AUTHOR: Gribouillis for the python forum at www.daniweb.com
import PythonMagick as Magick

in_name = 'scilab01.png'
out_name = 'scilab01_small.png'

img = Magick.Image(in_name)
geometry = img.size()
w, h = geometry.width(), geometry.height()
new_width = 800
factor = new_width/float(w)
new_height = int(h * factor)
img.resize("{}x{}".format(new_width, new_height))
img.write(out_name)

Is this work on C sharp? I have only tried to customize the size of images <URL SNIPPED> using the code below:

using System.IO;
using System.Drawing.Printing;
using Yiigo.Imaging;
using Yiigo.Imaging.Processing;

using YiigoImage Image = new YiigoImage();
{
string ImageID = (@"C:\ yiigo_example.jpg ");
float ImageWidth = "300";
float ImageHeight = "500";
}
Image.YiigoImageProcessResize(@"C:\ yiigo_example.jpg", "300", "500");
Image.Save(@"C:\ yiigo_example.jpg");

Is there any difference between them?

Edited 3 Years Ago by Gribouillis: commercial link

Dont like that there is no source code comment pointing out where to get it and that there is no info if it supports py3. Cant use it, downvote therefore.

Dont like that there is no source code comment pointing out where to get it and that there is no info if it supports py3. Cant use it, downvote therefore.

I did not write this with python 3 in mind. For windows you can download pythonmagick binaries for python 3 in Christoph Gohlke's site.

I was not able to install pythonmagick for python 3 in linux mint (as of November 24th 2013). You can use other python wrappers around ImageMagick however. For example I tried a ctypes wrapper magickpy, installed using pip3 (package python3-pip in linux mint). Here is the code

import magickpy as Magick

in_name = 'scilab02.png'
out_name = 'scilab02_small.png'

img = Magick.Image.read(in_name)
w, h = img.width, img.height
new_width = 800
factor = new_width/float(w)
new_height = int(h * factor)
info = Magick.ExceptionInfo()
filter = Magick.FilterTypes.BesselFilter
blur = 1.0
img2 = img.makeResize(new_width, new_height, filter, blur, info)
img2.write(out_name)

Aso check this page for other wrappers.

Edited 3 Years Ago by Gribouillis

Here is similar code for another ctypes binding to the imagemagick wand API.

from wand.image import Image

in_name = 'scilab02.png'
out_name = 'scilab02_small.png'

with Image(filename = in_name) as image:
    w, h = image.size
    new_width = 800
    factor = new_width/float(w)
    new_height = int(h * factor)
    image.resize(new_width, new_height, 'lanczos', 1.0)
    image.save(filename = out_name)

In mint, install module wand with pip3 for python 3 or with package python-wand for python 2.

Edited 3 Years Ago by Gribouillis

import PythonMagick

img = PythonMagick.Image("elixir.png")
img.resize("20%")
img.write('out_name.JPG')

# this works for me :)

Edited 2 Years Ago by Dani: Formatting fixed

Comments
Excellent! Conversion included!
The article starter is a financial contributor. Sponsored articles offer a bounty for quality replies.