Image resizing

Using v17 r3, Mac:
I am trying to resize some images. The resize functions just don’t have any effect. Here is my code:

C_PICTURE($pPicture)
BLOB TO PICTURE($bPicBlob;$pPicture;$FileExt)
PICTURE PROPERTIES($pPicture;$width;$height)
Case of
: ($width>115.2)
$scale:=(115.2/$width)
//TRANSFORM PICTURE($pPicture;Scale;$scale;$scale) // this has no effect
$pPicture:=$pPicture*$scale // this has no effect either
End case
WRITE PICTURE FILE($tExistingDocPathname;$pPicture;$FileExt) // $FileExt is TIF in this example

The final picture is the same size as the original.

Any ideas what I am doing wrong?

Thanks!
Pat

TRANSFORM picture is for most operations only a kind of rule, not a modification of the picture itself.

Scale does not change the size, but the Size, but the scale.
An image with 144 pixel width in a 72dpi resolution sized to 50% will be a 72 pixel width picture with 144 dpi. As result, the size in kilobyte is unchanged.

I assume you want to change/reduce size in kilobyte?

Try the following code and use TRACE to step through and monitor the variables

$path:=Get 4D folder(Current resources folder)+"Images:Buttons:LightGrey:Cancel.png"
read picture file($path;$pict)
$size:=Picture size($pict)
PICTURE PROPERTIES($pict;$width;$height)
TRANSFORM PICTURE($pict;Scale;0.5;0.5)
$size:=Picture size($pict)
PICTURE PROPERTIES($pict;$width;$height)
TRANSFORM PICTURE($pict;Crop;0;0;$width;$height)
$size:=Picture size($pict)

Hi Pat,
CREATE THUMBNAIL should do the job (i’m not shouting, that’s the command name):

$chemin_t:=Convert path POSIX to system("/Volumes/HD1To/Users/arnaud/myPicture.jpg")
READ PICTURE FILE($chemin_t;$image_i)
$largeur_l:=1000
$hauteur_l:=1000
CREATE THUMBNAIL($image_i;$imagette_i;$largeur_l;$hauteur_l)
SET PICTURE TO PASTEBOARD($image_i)

PS: no idea why, it seems I have to pass both parameters width and height equal, while the doc seems to say you can pass this 1st only:
CREATE THUMBNAIL ( source ; dest {; largeur {; hauteur {; mode {; profondeur}}}} )

as far as I remember I once heard that CREATE THUMBNAIL was created for thumbnails, and designed for that. Small, tiny images. I don’t think it uses the best possible code for large images.
As long the image width/height is small, like 64 or 128 pixel, fine.
For 1000 pixel, I think TRANSFORM could produce better results…

Hi Thomas,

CREATE THUMBNAIL is designed to build screen thumbnail. It means that you will lose original picture format, meta data…

Patrick

@Thomas_Maul
I tried before answering Pat with a 3876*2585 3,9Mb jpeg picture, the result was correct enough for me.

@patrick_poly
You know something about optional parameters width and height? It seems if I pass only the 1st, the result is always the default 48*48 picture. I suspect a typo in doc syntax.

Thanks Thomas.
In my testing, it seems to work correctly until I get to this line:

TRANSFORM PICTURE($pict;Crop;0;0;$width;$height)

This produces an empty picture (0 octets).

???
Pat

email footer pb.jpg

Hi Arnaud

For me the documentation is correct, and run time too. Check your thumbnail size, it should be correct.

Patrick

Hi Arnaud,
Thanks! But some of the images are .ai and .eps and they need to be maintained in that format.

Pat

email footer pb.jpg

Hi,

TRANSFORM PICTURE($pict;Crop;0;0;$width;$height) will have the same effect as CREATE THUMBNAIL.

If your picture is a PDF you will lose vector information…or meta data if your picture is a bitmap

Patrick

Hi @Thomas_Maul,
I’m not having a lot of success with this :frowning_face:
This is what I get:

BLOB TO PICTURE($blobPic;$Pict;$FileExt) // FileExt=“tif”
$size:=Picture size($pict) // $size=11618292
PICTURE PROPERTIES($pict;$width;$height) // width-320, height=320
TRANSFORM PICTURE($pict;Scale;0.5;0.5)
$size:=Picture size($pict) // $size=11618292
PICTURE PROPERTIES($pict;$width;$height) // width and height both=160 YES THIS IS THE RESULT I WANT!
WRITE PICTURE FILE($tExistingDocPathname;$pict;$FileExt)

Open the resulting picture and it’s the original size

If I insert the line:
TRANSFORM PICTURE($pict;Crop;0;0;$width;$height)
then the size of $pict is 0. It obliterates the picture :dizzy_face:

Another thing I am puzzled about …
The PICTURE PROPERTIES function tells me that the width and height of the picture are 320 pixels. But the picture is much bigger than that. If I open it up in Photoshop it’s 1500 pixels.

What am I doing wrong?

Thanks!

Pat

Hi,

Can you upload a the picture ?

Patrick

Here you go:

PB

Hi Pat,

Try this :

C_PICTURE($vi_image)
READ PICTURE FILE("Macintosh HD:Users:ble:Desktop:Style-77-3.tif.tiff";$vi_image)
  // picture is still 11 345 Kb, 300 dpi


C_LONGINT($vl_width;$vl_height)
PICTURE PROPERTIES($vi_image;$vl_width;$vl_height)
  // $vl_width : 1500 - $vl_height : 1459

$vr_ratio:=0.1

TRANSFORM PICTURE($vi_image;Scale;$vr_ratio;$vr_ratio)
  // picture is still 11 345 Kb
  // $vl_width : 150 - $vl_height : 145

WRITE PICTURE FILE("Macintosh HD:Users:ble:Desktop:Style-77-3_small.tiff";$vi_image)
  // picture written to disk is 89 Kb
  // $vl_width : 150 - $vl_height : 145, 300 dpi


TRANSFORM PICTURE($vi_image;Crop;0;0;$vl_width\$vr_ratio;$vl_height\$vr_ratio)
  // picture is now 18 Kb
  // $vl_width : 150 - $vl_height : 145
  // all meta data is gone (including resolution)

// you can force the resolution with these commands if you don't like the 72 dpi default after crop...
//SET PICTURE METADATA($vi_image;TIFF xResolution;300)
//SET PICTURE METADATA($vi_image;TIFF yResolution;300)

C_LONGINT($vl_width;$vl_height)
PICTURE PROPERTIES($vi_image;$vl_width;$vl_height)

WRITE PICTURE FILE("Macintosh HD:Users:ble:Desktop:Style-77-3_small2.tiff";$vi_image)
  // picture written to disk is 87 Kb
  // $vl_width : 150 - $vl_height : 145, 72 dpi

Question to 4D :

Why does TRANSFORM PICTURE($vi_image;Scale; …)
does not change the image size in Kb.
What do we need to do to get the image variable to be reduce in Kb ? To we need to write it to disk and reload it ? or is there a simple way to do this.

Replying to myslef,

I can do

PICTURE TO BLOB($vi_image;$vx_blob;".tif")
BLOB TO PICTURE($vx_blob;$vi_image)

but I need to know the codec of the image… So if there is a simpler way :wink:

Hi Bruno

TRANSFORM PICTURE scale/translate/flipH/flipV/ just set a transformation matrix on the picture, so the size does not change.
scale/translate/flipH/flipV can be canceled because source picture is not touched (check the doc)

You need to write the picture to disk or blob to get the new size

GET PICTURE FORMATS

Hello

The most simple way is "CONVERT PICTURE ( picture ; codec {; compression} ) "
Once this is done the image is really re-written with a changed size too.

Roland

Hi Roland,

Not in this case. Compression param does not change, source and destination codec are the same, the picture not be re encoded.

Patrick