Andre Wessels · Dec 21, 2019

How to resize an Image in classmethod

We need to resize existing images already in %GlobalBinaryStream  to create thumbnails.

The requirement is also to use the method to resize new images that are uploaded.


Does anyone have a solution for this ?

0 214
Discussion (2)2
Log in or sign up to continue

You could try this way (I assume, your image is in *.jpg, *.png, *.gif, *.ico or *.bmp  format and you use a Windows OS):

- save the stream to a temp file
- do $zf(-1,"pathToIrfanView.exe pathToInpFile  /resize=(100,100)  /aspectratio  /convert=pathToOutFile")
- read the output into a stream and proceed as needed

Don't forget, if one of the above path contains a space char, you have to put in quotes the whole path.

/resize=(100,100)  /aspectration  means, the picture will be resized to a max width/height of 100 by maintaning the aspect ratio. Example: input=2000x3000 out =67x100,  input=3000x2000  out=100x67

For Unix exists similar tools to use with $zf(-1,...), for example "identify" to get the dimensions of the picture  and "convert" or "imagemagick" for resizing.

I agree with general approach offered by @Julius Kavay, just wanted to add some notes:

1. Use $zf(-100) as a more secure alternative to $zf(-1) if it's available.

2. I'd go straight for imagemagick as it's crossplatform.

3. If speed is an issue you can consider using high-level MagickWand API (here's resize example) or low-level MagickCore API (here's resize functions) via Callout functionality. CoreAPI would be faster as there's in-memory image initializers so you can skip input/output file creation/consumption and work with inmemory streams.