예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function gamma($correction)
 {
     if (false === imagegammacorrect($this->resource, 1.0, $correction)) {
         throw new RuntimeException('Failed to apply gamma correction to the image');
     }
     return $this;
 }
예제 #2
0
function get_thumbnail($name, $xsize, $ysize)
{
    $thumbname = 'thumbs/' . $name . '_thumb_' . $xsize . '_' . $ysize . '.jpg';
    $fname = 'phpbb/files/' . $name;
    // Ignore the race condition, should only cause unnecessary work to be done at times
    if (!file_exists($thumbname)) {
        // Try to open it up with GD
        $image = @imagecreatefromjpeg($fname);
        if (!$image) {
            $image = @imagecreatefrompng($fname);
        }
        if (!$image) {
            $image = @imagecreatefromgif($fname);
        }
        // If we can't do it then this will have to suffice
        if (!$image) {
            return 'images/screen1.jpg';
        }
        // imagecopyresampled assumes images are at gamma 1.0, while they probably are at 2.2 (sRGB)
        // details and examples: http://www.4p8.com/eric.brasseur/gamma.html
        imagegammacorrect($image, 2.2, 1.0);
        $imageout = imagecreatetruecolor($xsize, $ysize);
        imagecopyresampled($imageout, $image, 0, 0, 0, 0, $xsize, $ysize, imagesx($image), imagesy($image));
        imagegammacorrect($imageout, 1.0, 2.2);
        imagejpeg($imageout, $thumbname);
    }
    return $thumbname;
}
예제 #3
0
 /**
  * {@inheritdoc}
  */
 public function gamma($correction)
 {
     if (false === imagegammacorrect($this->ressource, 1.0, $correction)) {
         throw new RuntimeException('Gamma correction failed');
     }
     return $this;
 }
예제 #4
0
 /**
  * Applies gamma correction to a given image
  *
  * @param  \Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $gamma = $this->argument(0)->type('numeric')->required()->value();
     foreach ($image as $frame) {
         imagegammacorrect($frame->getCore(), 1, $gamma);
     }
     return true;
 }
예제 #5
0
 /**
  * Executes imagegammacorrect()
  *
  * @param WideImage_Image $image
  * @param numeric $input_gamma
  * @param numeric $output_gamma
  * @return WideImage_TrueColorImage
  */
 function execute($image, $input_gamma, $output_gamma)
 {
     $new = $image->copy();
     if (!imagegammacorrect($new->getHandle(), $input_gamma, $output_gamma)) {
         throw new WideImage_GDFunctionResultException("imagegammacorrect() returned false");
     }
     return $new;
 }
예제 #6
0
파일: tc-lines.php 프로젝트: myfarms/PHPlot
function post_plot($img)
{
    global $tp;
    if (isset($tp['gamma'])) {
        imagegammacorrect($img, 1.0, $tp['gamma']);
    }
    if ($tp['savealpha']) {
        imagesavealpha($img, True);
    }
}
예제 #7
0
파일: Gamma.php 프로젝트: pyrsmk/imagix
 public function apply($resource)
 {
     @(list(, $input, $output) = func_get_args());
     $input = (double) $input;
     $output = (double) $output;
     if (!imagegammacorrect($resource, $input, $output)) {
         throw new Exception("Gamma correction failed");
     }
     return $resource;
 }
예제 #8
0
/**
 * Generate a thumbnail of a given file from the phpbb directory
 * 
 * @return string the path of the file, images/screen1.jpg on failure
 */
function get_thumbnail($name, $xsize, $ysize)
{
    $thumbname = 'thumbs/' . $name . '_thumb_' . $xsize . '_' . $ysize . '.jpg';
    $fname = 'phpbb/files/' . $name;
    // check if we can actually read the file
    if (!is_readable($fname)) {
        // we can't continue if we can't read the file
        return 'images/screen1.jpg';
    }
    // Ignore the race condition, should only cause unnecessary work to be done at times
    if (!file_exists($thumbname)) {
        // Try to open it up with GD
        $image = @imagecreatefromjpeg($fname);
        if (!$image) {
            $image = @imagecreatefrompng($fname);
        }
        if (!$image) {
            $image = @imagecreatefromgif($fname);
        }
        // If we can't do it then this will have to suffice
        if (!$image) {
            return 'images/screen1.jpg';
        }
        $srcw = imagesx($image);
        $srch = imagesy($image);
        $clipx = 0;
        $clipy = 0;
        $clipw = $srcw;
        $cliph = $srch;
        if ($xsize < $srcw * 0.5) {
            $maxclip = 0.8;
            $s = max($xsize / $srcw - $maxclip, 0.0) / (1.0 - $maxclip);
            $scale = $maxclip + (1.0 - $maxclip) * $s;
            $clipx = $srcw * (1.0 - $scale) / 2.0;
            $clipw = $srcw - $clipx * 2;
        }
        if ($ysize < $srch * 0.5) {
            $maxclip = 0.8;
            $s = max($ysize / $srch - $maxclip, 0.0) / (1.0 - $maxclip);
            $scale = $maxclip + (1.0 - $maxclip) * $s;
            $clipy = $srch * (1.0 - $scale) / 2.0;
            $cliph = $srch - $clipy * 2;
        }
        // imagecopyresampled assumes images are at gamma 1.0, while they probably are at 2.2 (sRGB)
        // details and examples: http://www.4p8.com/eric.brasseur/gamma.html
        imagegammacorrect($image, 2.2, 1.0);
        $imageout = imagecreatetruecolor($xsize, $ysize);
        imagecopyresampled($imageout, $image, 0, 0, $clipx, $clipy, $xsize, $ysize, $clipw, $cliph);
        imagegammacorrect($imageout, 1.0, 2.2);
        imagejpeg($imageout, $thumbname);
    }
    return $thumbname;
}
 public function make_grayscale()
 {
     // create a copy
     $dest = $this->image;
     unset($this->image);
     $this->load();
     if (is_resource($dest)) {
         // Apply grayscale filter
         imagecopymergegray($dest, $this->image, 0, 0, 0, 0, $this->size['width'], $this->size['height'], 0);
         imagegammacorrect($dest, 1.0, apply_filters('grayscale_gamma_correction', 0.7));
         imagedestroy($this->image);
         $this->image = $dest;
         return true;
     }
 }
예제 #10
0
파일: gen.php 프로젝트: bontiv/intrateb
 public function mkticket($data)
 {
     $this->reload_conf($data['type']);
     $this->img = $this->getimg($GLOBALS['genRoot'] . 'frames/' . $this->conf['img']);
     if (isset($this->conf['gamma'])) {
         imagegammacorrect($this->img, 1.0, $this->conf['gamma']);
     }
     if (isset($data['firstname']) && $data['firstname']) {
         $this->addtext($this->conf['firstname'], $data['firstname']);
     } else {
         $this->addblank($this->conf['firstname']);
     }
     if (isset($data['lastname']) && $data['lastname']) {
         $this->addtext($this->conf['lastname'], $data['lastname']);
     } else {
         $this->addblank($this->conf['lastname']);
     }
     if (isset($data['ticketid'])) {
         $this->addtext($this->conf['ticketid'], $data['ticketid']);
     }
     $this->addtext($this->conf['cb_label'], $data['barcode']);
     checksum($data['barcode']);
     writecode($this->img, $this->conf['codebar'], $data['barcode']);
 }
    /**
     * Change gamma
     *
     */
    private function gamma() {

        imagegammacorrect($this->im,1,$this->Gamma[1]);

    }
예제 #12
0
<?php

$image = imagecreate(150, 150);
$grey = imagecolorallocate($image, 6, 6, 6);
$gray = imagecolorallocate($image, 15, 15, 15);
$half = imagefilledarc($image, 75, 75, 70, 70, 0, 180, $grey, IMG_ARC_PIE);
$half2 = imagefilledarc($image, 75, 75, 70, 70, 0, -180, $gray, IMG_ARC_PIE);
$gamma = imagegammacorrect($image, 1, 5);
if ($gamma) {
    ob_start();
    imagepng($image, null, 9);
    $img = ob_get_contents();
    ob_end_clean();
}
echo md5(base64_encode($img));
예제 #13
0
 /**
  * gamma correction
  *
  * @param       float          gamma input
  * @param       float          gamma output
  * @return      ImageWriter
  */
 public function gamma($inputgamma, $outputgamma)
 {
     if (!is_null($this->imageResource)) {
         if (!imagegammacorrect($this->imageResource, (double) $inputgamma, (double) $outputgamma)) {
             throw new ImageWriterException('Gamma correction failed.');
         }
     }
     return $this;
 }
예제 #14
0
파일: image.php 프로젝트: jaz303/base-php
 public function correct_gamma($input_gamma, $output_gamma)
 {
     imagegammacorrect($this->gd, $input_gamma, $output_gamma);
 }
예제 #15
0
 /**
  * Resize the image proportionally to the given width/height
  *
  * Note: Some code used in this method is adapted from code found in comments at php.net for the GD functions
  *
  * @param int $targetWidth Target width in pixels, or 0 for proportional to height
  * @param int $targetHeight Target height in pixels, or 0 for proportional to width. Optional-if not specified, 0 is assumed.
  * @return bool True if the resize was successful
  *
  * @todo this method has become too long and needs to be split into smaller dedicated parts 
  *
  */
 public function ___resize($targetWidth, $targetHeight = 0)
 {
     $orientations = null;
     // @horst
     $needRotation = $this->autoRotation !== true ? false : ($this->checkOrientation($orientations) && (!empty($orientations[0]) || !empty($orientations[1])) ? true : false);
     $needResizing = true;
     // $this->isResizeNecessary($targetWidth, $targetHeight);
     //if(!$needResizing && !$needRotation) return true;
     $source = $this->filename;
     $dest = str_replace("." . $this->extension, "_tmp." . $this->extension, $source);
     $image = null;
     switch ($this->imageType) {
         // @teppo
         case IMAGETYPE_GIF:
             $image = @imagecreatefromgif($source);
             break;
         case IMAGETYPE_PNG:
             $image = @imagecreatefrompng($source);
             break;
         case IMAGETYPE_JPEG:
             $image = @imagecreatefromjpeg($source);
             break;
     }
     if (!$image) {
         return false;
     }
     if ($this->imageType != IMAGETYPE_PNG) {
         // @horst: linearize gamma to 1.0 - we do not use gamma correction with png because it doesn't respect transparency
         imagegammacorrect($image, 2.0, 1.0);
     }
     if ($needRotation) {
         // @horst
         $image = $this->imRotate($image, $orientations[0]);
         if ($orientations[0] == 90 || $orientations[0] == 270) {
             // we have to swap width & height now!
             $tmp = array($targetWidth, $targetHeight);
             $targetWidth = $tmp[1];
             $targetHeight = $tmp[0];
             $tmp = array($this->getWidth(), $this->getHeight());
             $this->setImageInfo($tmp[1], $tmp[0]);
         }
         if ($orientations[1] > 0) {
             $image = $this->imFlip($image, $orientations[1] == 2 ? true : false);
         }
     }
     if ($needResizing) {
         list($gdWidth, $gdHeight, $targetWidth, $targetHeight) = $this->getResizeDimensions($targetWidth, $targetHeight);
         $thumb = imagecreatetruecolor($gdWidth, $gdHeight);
         if ($this->imageType == IMAGETYPE_PNG) {
             // @adamkiss PNG transparency
             imagealphablending($thumb, false);
             imagesavealpha($thumb, true);
         } else {
             if ($this->imageType == IMAGETYPE_GIF) {
                 // @mrx GIF transparency
                 $transparentIndex = ImageColorTransparent($image);
                 $transparentColor = $transparentIndex != -1 ? ImageColorsForIndex($image, $transparentIndex) : 0;
                 if (!empty($transparentColor)) {
                     $transparentNew = ImageColorAllocate($thumb, $transparentColor['red'], $transparentColor['green'], $transparentColor['blue']);
                     $transparentNewIndex = ImageColorTransparent($thumb, $transparentNew);
                     ImageFill($thumb, 0, 0, $transparentNewIndex);
                 }
             } else {
                 $bgcolor = imagecolorallocate($thumb, 0, 0, 0);
                 imagefilledrectangle($thumb, 0, 0, $gdWidth, $gdHeight, $bgcolor);
                 imagealphablending($thumb, false);
             }
         }
         imagecopyresampled($thumb, $image, 0, 0, 0, 0, $gdWidth, $gdHeight, $this->image['width'], $this->image['height']);
         $thumb2 = imagecreatetruecolor($targetWidth, $targetHeight);
         if ($this->imageType == IMAGETYPE_PNG) {
             // @adamkiss PNG transparency
             imagealphablending($thumb2, false);
             imagesavealpha($thumb2, true);
         } else {
             if ($this->imageType == IMAGETYPE_GIF) {
                 // @mrx GIF transparency
                 if (!empty($transparentColor)) {
                     $transparentNew = ImageColorAllocate($thumb2, $transparentColor['red'], $transparentColor['green'], $transparentColor['blue']);
                     $transparentNewIndex = ImageColorTransparent($thumb2, $transparentNew);
                     ImageFill($thumb2, 0, 0, $transparentNewIndex);
                 }
             } else {
                 $bgcolor = imagecolorallocate($thumb2, 0, 0, 0);
                 imagefilledrectangle($thumb2, 0, 0, $targetWidth, $targetHeight, 0);
                 imagealphablending($thumb2, false);
             }
         }
         $w1 = $gdWidth / 2 - $targetWidth / 2;
         $h1 = $gdHeight / 2 - $targetHeight / 2;
         if (is_string($this->cropping)) {
             switch ($this->cropping) {
                 // @interrobang crop directions
                 case 'nw':
                     $w1 = 0;
                     $h1 = 0;
                     break;
                 case 'n':
                     $h1 = 0;
                     break;
                 case 'ne':
                     $w1 = $gdWidth - $targetWidth;
                     $h1 = 0;
                     break;
                 case 'w':
                     $w1 = 0;
                     break;
                 case 'e':
                     $w1 = $gdWidth - $targetWidth;
                     break;
                 case 'sw':
                     $w1 = 0;
                     $h1 = $gdHeight - $targetHeight;
                     break;
                 case 's':
                     $h1 = $gdHeight - $targetHeight;
                     break;
                 case 'se':
                     $w1 = $gdWidth - $targetWidth;
                     $h1 = $gdHeight - $targetHeight;
                     break;
                 default:
                     // center or false, we do nothing
             }
         } else {
             if (is_array($this->cropping)) {
                 // @interrobang + @u-nikos
                 if (strpos($this->cropping[0], '%') === false) {
                     $pointX = (int) $this->cropping[0];
                 } else {
                     $pointX = $gdWidth * ((int) $this->cropping[0] / 100);
                 }
                 if (strpos($this->cropping[1], '%') === false) {
                     $pointY = (int) $this->cropping[1];
                 } else {
                     $pointY = $gdHeight * ((int) $this->cropping[1] / 100);
                 }
                 if ($pointX < $targetWidth / 2) {
                     $w1 = 0;
                 } else {
                     if ($pointX > $gdWidth - $targetWidth / 2) {
                         $w1 = $gdWidth - $targetWidth;
                     } else {
                         $w1 = $pointX - $targetWidth / 2;
                     }
                 }
                 if ($pointY < $targetHeight / 2) {
                     $h1 = 0;
                 } else {
                     if ($pointY > $gdHeight - $targetHeight / 2) {
                         $h1 = $gdHeight - $targetHeight;
                     } else {
                         $h1 = $pointY - $targetHeight / 2;
                     }
                 }
             }
         }
         imagecopyresampled($thumb2, $thumb, 0, 0, $w1, $h1, $targetWidth, $targetHeight, $targetWidth, $targetHeight);
         if ($this->sharpening && $this->sharpening != 'none') {
             $image = $this->imSharpen($thumb2, $this->sharpening);
         }
         // @horst
     }
     // write to file
     $result = false;
     switch ($this->imageType) {
         case IMAGETYPE_GIF:
             // correct gamma from linearized 1.0 back to 2.0
             imagegammacorrect($thumb2, 1.0, 2.0);
             $result = imagegif($thumb2, $dest);
             break;
         case IMAGETYPE_PNG:
             // convert 1-100 (worst-best) scale to 0-9 (best-worst) scale for PNG
             $quality = round(abs(($this->quality - 100) / 11.111111));
             $result = imagepng($thumb2, $dest, $quality);
             break;
         case IMAGETYPE_JPEG:
             // correct gamma from linearized 1.0 back to 2.0
             imagegammacorrect($thumb2, 1.0, 2.0);
             $result = imagejpeg($thumb2, $dest, $this->quality);
             break;
     }
     @imagedestroy($image);
     // @horst
     if (isset($thumb) && is_resource($thumb)) {
         @imagedestroy($thumb);
     }
     // @horst
     if (isset($thumb2) && is_resource($thumb2)) {
         @imagedestroy($thumb2);
     }
     // @horst
     if ($result === false) {
         if (is_file($dest)) {
             @unlink($dest);
         }
         return false;
     }
     unlink($source);
     rename($dest, $source);
     // @horst: if we've retrieved IPTC-Metadata from sourcefile, we write it back now
     if ($this->iptcRaw) {
         $content = iptcembed($this->iptcPrepareData(), $this->filename);
         if ($content !== false) {
             $dest = preg_replace('/\\.' . $this->extension . '$/', '_tmp.' . $this->extension, $this->filename);
             if (strlen($content) == @file_put_contents($dest, $content, LOCK_EX)) {
                 // on success we replace the file
                 unlink($this->filename);
                 rename($dest, $this->filename);
             } else {
                 // it was created a temp diskfile but not with all data in it
                 if (file_exists($dest)) {
                     @unlink($dest);
                 }
             }
         }
     }
     $this->loadImageInfo($this->filename);
     $this->modified = true;
     return true;
 }
function tweak_wm_preview_images($ref, $rotateangle, $gamma, $extension = "jpg")
{
    $ps = sql_query("select * from preview_size where (internal=1 or allow_preview=1)");
    for ($n = 0; $n < count($ps); $n++) {
        $wm_file = get_resource_path($ref, true, $ps[$n]["id"], false, $extension, -1, 1, true);
        if (!file_exists($wm_file)) {
            return false;
        }
        list($sw, $sh) = @getimagesize($wm_file);
        $wm_source = imagecreatefromjpeg($wm_file);
        # Apply tweaks
        if ($rotateangle != 0) {
            # Use built-in function if available, else use function in this file
            if (function_exists("imagerotate")) {
                $wm_source = imagerotate($wm_source, $rotateangle, 0);
            } else {
                $wm_source = AltImageRotate($wm_source, $rotateangle);
            }
        }
        if ($gamma != 0) {
            imagegammacorrect($wm_source, 1.0, $gamma);
        }
        imagejpeg($wm_source, $wm_file, 95);
        list($tw, $th) = @getimagesize($wm_file);
        if ($rotateangle != 0) {
            $temp = $sw;
            $sw = $sh;
            $sh = $temp;
        }
        # Rescale image
        $wm_target = imagecreatetruecolor($sw, $sh);
        imagecopyresampled($wm_target, $wm_source, 0, 0, 0, 0, $sw, $sh, $tw, $th);
        imagejpeg($wm_target, $wm_file, 95);
    }
}
예제 #17
0
 /**
  * Applies gamma correction to a given image
  *
  * @param  \Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $gamma = $this->argument(0)->type('numeric')->required()->value();
     return imagegammacorrect($image->getCore(), 1, $gamma);
 }
예제 #18
0
 /**
  * Applies gamma correction
  *
  * @param  float $input
  * @param  float $output
  * @return Image
  */
 public function gamma($input, $output)
 {
     imagegammacorrect($this->resource, $input, $output);
     return $this;
 }
예제 #19
0
 public function washed()
 {
     imagefilter($this->image, IMG_FILTER_BRIGHTNESS, 30);
     imagefilter($this->image, IMG_FILTER_NEGATE);
     imagefilter($this->image, IMG_FILTER_COLORIZE, -50, 0, 20, 50);
     imagefilter($this->image, IMG_FILTER_NEGATE);
     imagefilter($this->image, IMG_FILTER_BRIGHTNESS, 10);
     imagegammacorrect($this->image, 1, 1.2);
     return $this;
 }
예제 #20
0
 public function effect($resource)
 {
     imagegammacorrect($resource, 1, 1.2);
     imagefilter($resource, IMG_FILTER_CONTRAST, -1);
     imagefilter($resource, IMG_FILTER_COLORIZE, 60, 20, 0, 50);
 }
 /**
  * Applies the filter to the resource
  *
  * @param ImageResource $aResource
  */
 public function applyFilter(ImageResource $aResource)
 {
     imagegammacorrect($aResource->getResource(), $this->input, $this->output);
 }
예제 #22
0
<?php

$image = imagecreatetruecolor(180, 30);
$gamma = imagegammacorrect($image, 1, 'string');
예제 #23
0
 /**
  * apply GammaCorrection to an image (@horst)
  * 
  * with mode = true it linearizes an image to 1
  * with mode = false it set it back to the originating gamma value
  *
  * @param GD-image-resource $image
  * @param boolean $mode
  *
  */
 protected function gammaCorrection(&$image, $mode)
 {
     if (-1 == $this->defaultGamma || !is_bool($mode)) {
         return;
     }
     if ($mode) {
         // linearizes to 1.0
         if (imagegammacorrect($image, $this->defaultGamma, 1.0)) {
             $this->gammaLinearized = true;
         }
     } else {
         if (!isset($this->gammaLinearized) || !$this->gammaLinearized) {
             return;
         }
         // switch back to original Gamma
         if (imagegammacorrect($image, 1.0, $this->defaultGamma)) {
             unset($this->gammaLinearized);
         }
     }
 }
예제 #24
0
 /**
  * Apply gamma correction to this image
  *
  * @param   float in
  * @param   float out
  * @return  bool success
  */
 public function correctGamma($in, $out)
 {
     return imagegammacorrect($this->handle, $in, $out);
 }
예제 #25
0
파일: GD.php 프로젝트: juniortux/jaws
 /**
  * Adjusts the image gamma
  *
  * @access  public
  * @param   float   $gamma
  * @return  mixed   True if success or a Jaws_Error on error
  */
 function gamma($gamma = 1.0)
 {
     $res = imagegammacorrect($this->_hImage, 1.0, $gamma);
     if (false === $res) {
         return Jaws_Error::raiseError('Failed transformation: gamma().', __FUNCTION__);
     }
     return true;
 }
예제 #26
0
 /**
  * Apply Gamma Correction for given gd resource
  * @param resource $virtual_image gd resource
  * @param float $level level of correction in range(0.01,4.99) where 1.00 = no change
  * @return boolean true on success false otherwise
  */
 public static function gamma($virtual_image, $level)
 {
     if (@get_resource_type($virtual_image) != TIP_RT) {
         self::logger("gamma", " Not A GD Resource");
         return false;
     }
     self::activateAlphaChannel($virtual_image);
     $level = (double) $level;
     $level = $level >= 0.01 && $level <= 4.99 ? $level : 1.0;
     return @imagegammacorrect($virtual_image, 1.0, $level);
 }
예제 #27
0
 /**
  * Executes imagegammacorrect()
  *
  * @param WideImage_Image $image
  * @param numeric $input_gamma
  * @param numeric $output_gamma
  * @return WideImage_TrueColorImage
  */
 function execute($image, $input_gamma, $output_gamma)
 {
     $new = $image->copy();
     imagegammacorrect($new->getHandle(), $input_gamma, $output_gamma);
     return $new;
 }
예제 #28
0
 /**
  * {@inheritdoc}
  */
 protected function doApply(CanvasInterface $canvas)
 {
     imagegammacorrect($canvas->getHandler(), 1.0, $this->getLevel());
 }
 /**
  * Apply the transform to the sfImage object.
  *
  * @param sfImage
  * @return sfImage
  */
 protected function transform(sfImage $image)
 {
     $resource = $image->getAdapter()->getHolder();
     imagegammacorrect($resource, $this->input_gamma, $this->output_gamma);
     return $image;
 }
예제 #30
0
파일: Filter.php 프로젝트: CeusMedia/Image
 public function gamma($level)
 {
     return imagegammacorrect($this->image->getResource(), 1.0, (double) $level);
 }