2

So I'm currently using the following script on my synology nas webstation to resize images one at a time. It is being called by a post function on another page every time the previous request has been handled.

$originalFile = 'img1.jpg';
$smallFile = 'img1_small.jpg';
$percentage = 0.2;
$mktime = date('Y-m-d H:i:s', filemtime($originalFile));
$img = imagecreatefromjpeg($originalFile);
list($width, $height) = getimagesize($originalFile);

    if(function_exists("exif_read_data")){

        $exif = @exif_read_data($originalFile);

            if(!empty($exif['Orientation'])) {

                switch($exif['Orientation']) {
                    case 8:
                            $img = imagerotate($img,90,0);
                                list($height, $width) = getimagesize($originalFile);
                                break;
                    case 3:
                        $img = imagerotate($img,180,0);
                        break;
                    case 6:
                        $img = imagerotate($img,-90,0);
                        list($height, $width) = getimagesize($originalFile);
                        break;
                }
            }
    }
    $newWidth = ceil($percentage * $width);
    $newHeight = ceil($percentage * $height);

    $resized = imagecreatetruecolor($newWidth, $newHeight);
    imagecopyresampled($resized, $img, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
    imagejpeg($resized, $smallFile, 100);
    imagedestroy($resized);

The images are images coming from a camera so they are almost he greatest quality you can get. The issue here is that i'm not able to run imagick on my nas. I would not know how to install this for php.

Is there any smart way to speed up the process I am doing here? BTW. I am running some sql scripts as well so I'd like to keep doing this using php.

Dhruv
  • 612
  • 7
  • 15
Mart
  • 475
  • 4
  • 21

1 Answers1

1

There is a community repository, which has imagick. https://synocommunity.com/ https://synocommunity.com/package/imagemagick

Step 1 Log into your NAS as administrator and go to Main Menu → Package Center → Settings and set Trust Level to Synology Inc. and trusted publishers.

Step 2 In the Package Sources tab, click Add, type SynoCommunity as Name and http://packages.synocommunity.com/ as Location and then press OK to validate.

Step 3 Go back to the Package Center and enjoy SynoCommunity's packages in the Community tab.

Depending on your Synology, it might be an idea to use Docker for this task, instead of installing directly Imagick onto your synology.

user5542121
  • 1,051
  • 12
  • 28
  • 1
    This package does not work with the PHP package on a synology nas, hence, this package will not do as asked in my question. – Mart Jun 13 '19 at 21:03
  • Theoeretically you should be able to call the executable, through exec. But yes the code as such has to be adapted. Since there is no build available, I would go that way. – user5542121 Jun 14 '19 at 08:58