Exemplo n.º 1
0
 public function write($ps_filepath, $mimetype)
 {
     if (!$this->handle) {
         return false;
     }
     if (strpos($ps_filepath, ':') && caGetOSFamily() != OS_WIN32) {
         $this->postError(1610, _t("Filenames with colons (:) are not allowed"), "WLPlugGmagick->write()");
         return false;
     }
     if ($mimetype == "image/tilepic") {
         if ($this->properties["mimetype"] == "image/tilepic") {
             copy($this->filepath, $ps_filepath);
         } else {
             $tp = new TilepicParser();
             if (!($properties = $tp->encode($this->filepath, $ps_filepath, array("tile_width" => $this->properties["tile_width"], "tile_height" => $this->properties["tile_height"], "layer_ratio" => $this->properties["layer_ratio"], "quality" => $this->properties["quality"], "antialiasing" => $this->properties["antialiasing"], "output_mimetype" => $this->properties["tile_mimetype"], "layers" => $this->properties["layers"])))) {
                 $this->postError(1610, $tp->error, "WLPlugTilepic->write()");
                 return false;
             }
         }
         # update mimetype
         foreach ($properties as $k => $v) {
             $this->properties[$k] = $v;
         }
         $this->properties["mimetype"] = "image/tilepic";
         $this->properties["typename"] = "Tilepic";
         return 1;
     } else {
         # is mimetype valid?
         if (!($ext = $this->info["EXPORT"][$mimetype])) {
             # this plugin can't write this mimetype
             return false;
         }
         $this->handle->setimageformat($this->magick_names[$mimetype]);
         # set quality
         if ($this->properties["quality"] && $this->properties["mimetype"] != "image/tiff") {
             $this->handle->setcompressionquality($this->properties["quality"]);
         }
         $this->handle->setimagebackgroundcolor(new GmagickPixel("#CC0000"));
         if ($this->properties['gamma']) {
             if (!$this->properties['reference-black']) {
                 $this->properties['reference-black'] = 0;
             }
             if (!$this->properties['reference-white']) {
                 $this->properties['reference-white'] = 65535;
             }
             $this->handle->levelimage($this->properties['reference-black'], $this->properties['gamma'], $this->properties['reference-white']);
         }
         $this->handle->stripimage();
         // remove all lingering metadata
         # write the file
         try {
             if (!$this->handle->writeimage($ps_filepath . "." . $ext)) {
                 $this->postError(1610, _t("Error writing file"), "WLPlugGmagick->write()");
                 return false;
             }
             if (!file_exists($ps_filepath . "." . $ext)) {
                 if ($this->handle->getnumberimages() > 1) {
                     if (file_exists($ps_filepath . "-1." . $ext)) {
                         @rename($ps_filepath . "-0." . $ext, $ps_filepath . "." . $ext);
                         $this->properties["mimetype"] = $mimetype;
                         $this->properties["typename"] = $this->handle->getimageformat();
                         // get rid of other pages
                         $i = 1;
                         while (file_exists($vs_f = $ps_filepath . "-" . $i . "." . $ext)) {
                             @unlink($vs_f);
                             $i++;
                         }
                         return $ps_filepath . "." . $ext;
                     }
                 }
                 $this->postError(1610, _t("Error writing file"), "WLPlugGmagick->write()");
                 return false;
             }
         } catch (Exception $e) {
             $this->postError(1610, _t("Error writing file: %1", $e->getMessage()), "WLPlugGmagick->write()");
             return false;
         }
         # update mimetype
         $this->properties["mimetype"] = $mimetype;
         $this->properties["typename"] = $this->handle->getimageformat();
         return $ps_filepath . "." . $ext;
     }
 }
Exemplo n.º 2
0
 public function write($filepath, $mimetype)
 {
     if (!$this->handle) {
         return false;
     }
     // 75 is about the default value of imagejpeg() so it seems like a reasonable default for us as well
     $vn_jpeg_quality = isset($this->properties["quality"]) && $this->properties["quality"] ? intval($this->properties["quality"]) : 75;
     if ($mimetype == "image/tilepic") {
         if ($this->properties["mimetype"] == "image/tilepic") {
             copy($this->filepath, $filepath);
         } else {
             $tp = new TilepicParser();
             $tp->useLibrary(LIBRARY_GD);
             if (!($properties = $tp->encode($this->filepath, $filepath, array("tile_width" => $this->properties["tile_width"], "tile_height" => $this->properties["tile_height"], "layer_ratio" => $this->properties["layer_ratio"], "quality" => $vn_jpeg_quality, "antialiasing" => $this->properties["antialiasing"], "output_mimetype" => $this->properties["tile_mimetype"], "layers" => $this->properties["layers"])))) {
                 $this->postError(1610, $tp->error, "WLPlugTilepic->write()");
                 return false;
             }
         }
         # update mimetype
         foreach ($properties as $k => $v) {
             $this->properties[$k] = $v;
         }
         $this->properties["mimetype"] = "image/tilepic";
         $this->properties["typename"] = "Tilepic";
         return $filepath;
     } else {
         # is mimetype valid?
         if (!($ext = $this->info["EXPORT"][$mimetype])) {
             # this plugin can't write this mimetype
             return false;
         }
         # get layer out of Tilepic
         if ($this->properties["mimetype"] == "image/tilepic") {
             if (!($h = $this->handle->getLayer($this->properties["output_layer"] ? $this->properties["output_layer"] : intval($this->properties["layers"] / 2.0), $mimetype))) {
                 $this->postError(1610, $this->handle->error, "WLPlugTilepic->write()");
                 return false;
             }
             $this->handle = $h;
         }
         $vn_res = 0;
         switch ($mimetype) {
             case 'image/gif':
                 $vn_res = imagegif($this->handle, $filepath . "." . $ext);
                 $vs_typename = "GIF";
                 break;
             case 'image/jpeg':
                 $vn_res = imagejpeg($this->handle, $filepath . "." . $ext, $vn_jpeg_quality);
                 $vs_typename = "JPEG";
                 break;
             case 'image/png':
                 $vn_res = imagepng($this->handle, $filepath . "." . $ext);
                 $vs_typename = "PNG";
                 break;
         }
         # write the file
         if (!$vn_res) {
             # error
             $this->postError(1610, _t("Couldn't write image"), "WLPlugGD->write()");
             return false;
         }
         # update mimetype
         $this->properties["mimetype"] = $mimetype;
         $this->properties["typename"] = $vs_typename;
         return $filepath . "." . $ext;
     }
 }
Exemplo n.º 3
0
 public function write($filepath, $mimetype)
 {
     if (!$this->handle) {
         return false;
     }
     if (strpos($filepath, ':') && caGetOSFamily() != OS_WIN32) {
         $this->postError(1610, _t("Filenames with colons (:) are not allowed"), "WLPlugImageMagick->write()");
         return false;
     }
     if ($mimetype == "image/tilepic") {
         if ($this->properties["mimetype"] == "image/tilepic") {
             copy($this->filepath, $filepath);
         } else {
             $tp = new TilepicParser();
             if (!($properties = $tp->encode($this->filepath, $filepath, array("tile_width" => $this->properties["tile_width"], "tile_height" => $this->properties["tile_height"], "layer_ratio" => $this->properties["layer_ratio"], "quality" => $this->properties["quality"], "antialiasing" => $this->properties["antialiasing"], "output_mimetype" => $this->properties["tile_mimetype"], "layers" => $this->properties["layers"])))) {
                 $this->postError(1610, $tp->error, "WLPlugTilepic->write()");
                 return false;
             }
         }
         # update mimetype
         foreach ($properties as $k => $v) {
             $this->properties[$k] = $v;
         }
         $this->properties["mimetype"] = "image/tilepic";
         $this->properties["typename"] = "Tilepic";
         return 1;
     } else {
         # is mimetype valid?
         if (!($ext = $this->info["EXPORT"][$mimetype])) {
             # this plugin can't write this mimetype
             return false;
         }
         if (!$this->_graphicsMagickWrite($this->handle, $filepath . "." . $ext, $mimetype, $this->properties["quality"])) {
             $this->postError(1610, _t("Could not write file %1", $filepath . "." . $ext), "WLPlugImageMagick->write()");
             return false;
         }
         # update mimetype
         $this->properties["mimetype"] = $mimetype;
         $this->properties["typename"] = $this->magick_names[$mimetype];
         return $filepath . "." . $ext;
     }
 }