Velden,
It works like a charm...
There is unexpected behavior. If I use event manager ->PostItemSave then the pdf file (my custom field (send file)in Lise) is not uploaded.
My UDT:
Code: Select all
$im = new Imagick();
$obj = $params['item_object'];
$fd = $obj->fielddefs['sendfile'];
$ft = 'uploads/batimac/'.$fd->value;
$im->readImage($ft);
$im->setResolution(72,72);
$im->setBackgroundColor('white');
$compression_type = Imagick::COMPRESSION_JPEG;
$im->setImageCompression($compression_type);
$im->setImageCompressionQuality(19);
$im->mergeImageLayers(Imagick::LAYERMETHOD_FLATTEN);
$im->setImageAlphaChannel(Imagick::VIRTUALPIXELMETHOD_WHITE);
$im->setIteratorIndex(0);
$debtamps = bin2hex(random_bytes(5));
$afinalname = "slide-".$debtamps;
$finalname=uniqid($afinalname).".jpg";
$im->setGravity(\Imagick::GRAVITY_CENTER);
$geo=$im->getImageGeometry();
$sizex=$geo['width'];
$sizey=$geo['height'];
$ratio=$sizex/$sizey;
if ($sizex>600){
if ($ratio>1) {$im->scaleImage(480,560,true);$im->cropThumbnailImage(240,310);}
else {$im->scaleImage(240,320,true);}}
else {echo "<span class='careful'> to small pdf</span>";}
Then I get an error "
"Fatal error: Uncaught ImagickException: unable to open image 'uploads/batimac/test5.pdf'".
I dont understand. It seems that the user tag is executed before the saving of the item and that it prevents the sending of the file.
The line
seems to generate the error.
If i use my udt in Lise summary template
and I use
, it works...
That's not all, if I succeed in making this work, I will have to manage to retrieve the url of the generated image and make sure that a custom field of type inputtext in Lise takes this value. .
Suffice to say that we will surely have to play with the database ... The 12 labors of Hercule, for me ..