Create also an thumbnail with PHPthumb

I’m searching for a way to create also an thumbnail for an uploaded image.

I can do it with add this code to row_inserting & row_updating

$file=$rsnew['afbeelding1'];
$this->afbeelding1->Upload->resizeAndSaveToFile(100, 100, 80, "../images/content/thumbs2/",$file, TRUE);

But I want to use PHPthumb so I can use adaptiveResize. I can manage to adaptiveResize the original image with this code

$this->afbeelding1->Upload->Plugins[] = function($thumb) {
$thumb->adaptiveResize(175, 175);
    };

But I’m not able to use phpThumb to make an extra thumbnail version of the image.

You used resizeAndSaveToFile() wrongly, from source code, the arguments are: (v2022)

    /**
     * Resize and save uploaded data to file
     *
     * @param int $width Target width of image
     * @param int $height Target height of image
     * @param int $quality Deprecated, kept for backward compatibility only.
     * @param string $newFileName New file name
     * @param bool $overWrite Overwrite existing file or not
     * @param int $idx optional Index of the file
     * @return HttpUpload
     */
    public function resizeAndSaveToFile($width, $height, $quality, $newFileName, $overWrite, $idx = -1)

I want to use PHPthumb for the thumb creation, but I don’t now how.So I can use adaptiveResize.

But now I only been able to make a thumb normal resize with resizeandsavetofile.Or use PHPthumb but than I can only resize the source file not make an extra file (thumb)

Note that after resizing, the image of the PHPthumb will be updated (smaller), so if you need another image which is larger, you should create the larger one first. For example, if want two images one is 100x100, the another 175x175, you should set the resize dimensions in Edit Tag as 100x100 and make the larger one (175x175) first in server event, e.g.

$this->MyField->Upload->Plugins[] = function($thumb) {
    $thumb->adaptiveResize(175, 175)->save("my/path/myfile.ext"); // If you need to check the format to determine the extension name, you may check $thumb->format which should return 'GIF' or 'JPG' or 'PNG'.
};

Then the normal execution of script will continue to resize the image to 100x100.

I tried something like this, but I don’t get the current filename

$this->afbeelding1->Upload->Plugins[] = function($thumb) {
$path1="../images/content/thumbs/";
$path1.= $rsnew["photo"];
$thumb->adaptiveResize(12, 16)->save($path1);
};

how can I get filename and is there a way to config jpg compression

See PHP Thumb docs, you may use getFileName() and setOptions(). See supported options here.