Sample Header Ad - 728x90

Reshape an image with ImageMagick

3 votes
1 answer
106 views
I know I can resize a image with ImageMagick using -resize or -scale, but how can I ***reshape*** a image with ImageMagick? If I use -resize or -scale: magick image.png -resize 160x a.png magick image.png -scale 160x b.png I will get this: enter image description here But I want to have exactly the same number of pixels with exactly the same values in exactly the same order, but they will be *"re-flowed"* if that is a word into a different shape. I have already worked out how to do it with Python Imaging Library and Numpy. My starting image is 80x80 and looks like this: enter image description here from PIL import Image import numpy as np image = Image.open('a.png').convert('RGB') npArray = np.array(image) Image.fromarray(npArray.reshape(-1,160,3)).save('largeur160.png') Image.fromarray(npArray.reshape(-1,40,3)).save('largeur40.png') Image.fromarray(npArray.reshape(-1,10,3)).save('largeur10.png') I get these images with width 160, and 40 and 10: enter image description here enter image description here enter image description here
Asked by Sophie Bertillon (83 rep)
Aug 25, 2024, 09:17 AM
Last activity: Aug 25, 2024, 09:52 AM