function correct($path)
 {
     // Уменьшаем до максимально допустимых размеров
     //var_dump($path);
     $img = new \Image($path);
     $img->resize(1500, 1500, false, false);
     if ($this->fw->get('site.use_watermark')) {
         $overlay = new \Image('../' . APP_FOLDER . '/views/' . $this->fw->get('site.tpl') . '/watermark.png');
         $overlay->resize(1500, 1500, true, false);
         $img->overlay($overlay, (int) $this->fw->get('site.watermark.x') | (int) $this->fw->get('site.watermark.y'));
     } elseif ($this->fw->get('site.use_text_watermark')) {
         // Создаём изображение-оверлей с надписью
         $wm = $this->createTextWatermark($img->width(), $img->height());
         $overlay = new \Image($wm);
         // 2 добавить его к текущему изборажению
         $img->overlay($overlay, \Image::POS_Center | \Image::POS_Middle);
     }
     $this->fw->write($path, $img->dump());
 }
Beispiel #2
0
 protected function insertImage($id, $values)
 {
     $request = Request::getInstance();
     // get settings
     $searchcriteria = array('tree_id' => $values['tree_id'], 'tag' => $values['tag']);
     $settings = $this->getSettings($searchcriteria);
     $destWidth = $settings['image_width'];
     $destHeight = $settings['image_height'];
     $maxWidth = $settings['image_max_width'];
     $imgX = $values['img_x'];
     $imgY = $values['img_y'];
     $path = $this->plugin->getContentPath(true);
     $filename = strtolower($this->getClassName()) . "_" . $id['id'];
     // check if image is uploaded
     $img = $values['image'];
     $upload = is_array($img) && $img['tmp_name'];
     if ($upload) {
         // image is new uploaded image
         $image = new Image($img);
         $imgWidth = $image->getWidth();
         $imgHeight = $image->getHeight();
         $ext = Utils::getExtension($img['name']);
         $originalFile = $filename . "_tmp.{$ext}";
         $croppedFile = "{$filename}.{$ext}";
         // delete current image if filename new filename is different
         $detail = $this->getDetail($id);
         if ($detail['image_temp'] && $detail['image_temp'] != $originalFile) {
             $this->deleteImage($detail);
         }
         // resize original image. (increase size if necessary)
         if ($maxWidth > 0 && $imgWidth > $maxWidth) {
             $image->resize($maxWidth);
         } elseif ($imgWidth < $destWidth || $imgHeight < $destHeight) {
             if ($image->getWidth() < $destWidth) {
                 $image->resize($destWidth, 0, true);
             }
             if ($image->getHeight() < $destHeight) {
                 $image->resize(0, $destHeight, true);
             }
         }
         $image->save($path . $originalFile);
     } else {
         // no image provided. check if one exists
         $detail = $this->getDetail($id);
         if (!$detail['image_temp']) {
             return;
         }
         // get original image
         $image = new Image($detail['image_temp'], $this->plugin->getContentPath(true));
         $ext = Utils::getExtension($detail['image']);
         $originalFile = $filename . "_tmp.{$ext}";
         $croppedFile = "{$filename}.{$ext}";
     }
     // only crop if both width and height settings are set and image is big enough, else do a resize
     if ($destWidth && $destHeight) {
         // crop image
         if ($upload) {
             // calculate area of crop field
             // first assume width is smalles side
             $newWidth = $image->getWidth();
             $newHeight = $newWidth / $destWidth * $destHeight;
             if ($newHeight > $image->getHeight()) {
                 // width was larger than height, so use height as smallest side
                 $newHeight = $image->getHeight();
                 $newWidth = $newHeight / $destHeight * $destWidth;
             }
             // center crop area
             $imgX = intval($image->getWidth() / 2 - $newWidth / 2);
             $imgY = intval($image->getHeight() / 2 - $newHeight / 2);
         } else {
             $newWidth = $values['img_width'];
             $newHeight = $values['img_height'];
         }
         // crop image
         $image->crop($imgX, $imgY, $newWidth, $newHeight, $destWidth, $destHeight);
         // add overlay to  image
         if ($settings['image']) {
             $layerImg = new Image($settings['image'], $this->plugin->getContentPath(true));
             $image->overlay($layerImg);
         }
         // save cropped and overlayed image
         $image->save($path . $croppedFile);
     } else {
         // resize image
         $image->resize($destWidth, $destHeight);
         $newWidth = $image->getWidth();
         $newHeight = $image->getHeight();
         $image->save($path . $croppedFile);
     }
     $db = $this->getDb();
     $query = sprintf("update banner set bnr_image= '%s', bnr_image_temp = '%s', bnr_img_x = %d, bnr_img_y = %d, bnr_img_width = %d, bnr_img_height = %d where bnr_id = %d", addslashes($croppedFile), addslashes($originalFile), $imgX, $imgY, $newWidth, $newHeight, $id['id']);
     $res = $db->query($query);
     if ($db->isError($res)) {
         throw new Exception($res->getDebugInfo());
     }
 }