Пример #1
0
 function createimage()
 {
     $this->calculate();
     $r = $this->radius;
     //$image=imagecreate($r*3,$r*2); // Modified by Elpidio Latorilla 2003-04-23
     $image = imagecreate($r * 2, $r * 2);
     $white = imagecolorallocate($image, 255, 255, 255);
     $black = imagecolorallocate($image, 0, 0, 0);
     imagecolorTransparent($image, $white);
     for ($k = 0; $k < count($this->colors); $k++) {
         $fillcolor[$k] = imagecolorallocate($image, $this->colornames[$this->colors[$k]][0], $this->colornames[$this->colors[$k]][1], $this->colornames[$this->colors[$k]][2]);
     }
     imagearc($image, $r, $r, $r * 2 - 1, $r * 2 - 1, 0, 360, $black);
     imagefill($image, $r, $r, $fillcolor[0]);
     for ($j = 0; $j < count($this->elements); $j++) {
         $degree += 360 * $this->fractions[$j];
         if ($this->elements[$j]) {
             imageline($image, $r, $r, $r + $r * cos($degree * pi() / 180), $r + $r * sin($degree * pi() / 180), $black);
             imagefill($image, $r + 15 * cos(($degree + 5) * pi() / 180), $r + 15 * sin(($degree + 5) * pi() / 180), $fillcolor[$j]);
         }
         // Modified by Elpidio Latorilla 2003-04-23
         //imagefilledrectangle($image,2.1*$r,.7*$r+($r/15)*$j,2.12*$r+($r/25),.7*$r+5+($r/15)*$j,$fillcolor[$j]);
         //imagestring($image,0,2.13*$r+$r/20,.71*$r+($r/15)*$j-2,$this->elements[$j]."-".$this->elementnames[$j],$black);
     }
     $this->final = $image;
 }
Пример #2
0
 public function resize($width, $height, $createNew = true, $scaleMethod = self::SCALE_INSIDE)
 {
     if (!$this->isLoaded()) {
         throw new LogicException('No valid image was loaded.');
     }
     $width = $this->sanitizeWidth($width, $height);
     $height = $this->sanitizeHeight($height, $width);
     $dimensions = $this->prepareDimensions($width, $height, $scaleMethod);
     $offset = new stdClass();
     $offset->x = $offset->y = 0;
     if ($scaleMethod == self::SCALE_FIT) {
         $offset->x = round(($width - $dimensions->width) / 2);
         $offset->y = round(($height - $dimensions->height) / 2);
         $handle = imagecreatetruecolor($width, $height);
         if (!$this->isTransparent()) {
             $transparency = imagecolorAllocateAlpha($this->handle, 0, 0, 0, 127);
             imagecolorTransparent($this->handle, $transparency);
         }
     } else {
         $handle = imagecreatetruecolor($dimensions->width, $dimensions->height);
     }
     imagealphablending($handle, false);
     imagesavealpha($handle, true);
     if ($this->isTransparent()) {
         $rgba = imageColorsForIndex($this->handle, imagecolortransparent($this->handle));
         $color = imageColorAllocateAlpha($this->handle, $rgba['red'], $rgba['green'], $rgba['blue'], $rgba['alpha']);
         imagecolortransparent($handle, $color);
         imagefill($handle, 0, 0, $color);
         imagecopyresized($handle, $this->handle, $offset->x, $offset->y, 0, 0, $dimensions->width, $dimensions->height, $this->getWidth(), $this->getHeight());
     } else {
         imagecopyresampled($handle, $this->handle, $offset->x, $offset->y, 0, 0, $dimensions->width, $dimensions->height, $this->getWidth(), $this->getHeight());
     }
     if ($createNew) {
         $new = new JImage($handle);
         return $new;
     } else {
         $this->destroy();
         $this->handle = $handle;
         return $this;
     }
 }
Пример #3
0
 /**
  * Method to resize the current image.
  *
  * @param   mixed    $width        The width of the resized image in pixels or a percentage.
  * @param   mixed    $height       The height of the resized image in pixels or a percentage.
  * @param   boolean  $createNew    If true the current image will be cloned, resized and returned; else
  *                                 the current image will be resized and returned.
  * @param   integer  $scaleMethod  Which method to use for scaling
  *
  * @return  Image
  *
  * @since   1.0
  * @throws  \LogicException
  */
 public function resize($width, $height, $createNew = true, $scaleMethod = self::SCALE_INSIDE)
 {
     // Make sure the resource handle is valid.
     if (!$this->isLoaded()) {
         throw new \LogicException('No valid image was loaded.');
     }
     // Sanitize width.
     $width = $this->sanitizeWidth($width, $height);
     // Sanitize height.
     $height = $this->sanitizeHeight($height, $width);
     // Prepare the dimensions for the resize operation.
     $dimensions = $this->prepareDimensions($width, $height, $scaleMethod);
     // Instantiate offset.
     $offset = new \stdClass();
     $offset->x = $offset->y = 0;
     // Center image if needed and create the new truecolor image handle.
     if ($scaleMethod == self::SCALE_FIT) {
         // Get the offsets
         $offset->x = round(($width - $dimensions->width) / 2);
         $offset->y = round(($height - $dimensions->height) / 2);
         $handle = imagecreatetruecolor($width, $height);
         // Make image transparent, otherwise canvas outside initial image would default to black
         if (!$this->isTransparent()) {
             $transparency = imagecolorAllocateAlpha($this->handle, 0, 0, 0, 127);
             imagecolorTransparent($this->handle, $transparency);
         }
     } else {
         $handle = imagecreatetruecolor($dimensions->width, $dimensions->height);
     }
     // Allow transparency for the new image handle.
     imagealphablending($handle, false);
     imagesavealpha($handle, true);
     if ($this->isTransparent()) {
         // Get the transparent color values for the current image.
         $rgba = imageColorsForIndex($this->handle, imagecolortransparent($this->handle));
         $color = imageColorAllocateAlpha($this->handle, $rgba['red'], $rgba['green'], $rgba['blue'], $rgba['alpha']);
         // Set the transparent color values for the new image.
         imagecolortransparent($handle, $color);
         imagefill($handle, 0, 0, $color);
     }
     // Use resampling for better quality
     imagecopyresampled($handle, $this->handle, $offset->x, $offset->y, 0, 0, $dimensions->width, $dimensions->height, $this->getWidth(), $this->getHeight());
     // If we are resizing to a new image, create a new JImage object.
     if ($createNew) {
         // @codeCoverageIgnoreStart
         $new = new Image($handle);
         return $new;
         // @codeCoverageIgnoreEnd
     } else {
         // Free the memory from the current handle
         $this->destroy();
         $this->handle = $handle;
         return $this;
     }
 }
Пример #4
0
 /**
  * Method to resize the current image.
  *
  * @param   mixed    $width        The width of the resized image in pixels or a percentage.
  * @param   mixed    $height       The height of the resized image in pixels or a percentage.
  * @param   boolean  $createNew    If true the current image will be cloned, resized and returned; else
  *                                 the current image will be resized and returned.
  * @param   integer  $scaleMethod  Which method to use for scaling
  *
  * @return  KunenaImage
  *
  * @since   11.3
  * @throws  LogicException
  */
 public function resize($width, $height, $createNew = true, $scaleMethod = self::SCALE_INSIDE)
 {
     $config = KunenaFactory::getConfig();
     switch ($config->avatarresizemethod) {
         case '0':
             $resizemethod = 'imagecopyresized';
             break;
         case '1':
             $resizemethod = 'imagecopyresampled';
             break;
         default:
             $resizemethod = 'self::imageCopyResampledBicubic';
             break;
     }
     // Make sure the resource handle is valid.
     if (!$this->isLoaded()) {
         throw new LogicException('No valid image was loaded.');
     }
     // Sanitize width.
     $width = $this->sanitizeWidth($width, $height);
     // Sanitize height.
     $height = $this->sanitizeHeight($height, $width);
     // Prepare the dimensions for the resize operation.
     $dimensions = $this->prepareDimensions($width, $height, $scaleMethod);
     // Instantiate offset.
     $offset = new stdClass();
     $offset->x = $offset->y = 0;
     // Get truecolor handle
     $handle = imagecreatetruecolor($dimensions->width, $dimensions->height);
     // Center image if needed and create the new truecolor image handle.
     if ($scaleMethod == self::SCALE_FIT) {
         // Get the offsets
         $offset->x = round(($width - $dimensions->width) / 2);
         $offset->y = round(($height - $dimensions->height) / 2);
         // Make image transparent, otherwise cavas outside initial image would default to black
         if (!$this->isTransparent()) {
             $transparency = imagecolorAllocateAlpha($this->handle, 0, 0, 0, 127);
             imagecolorTransparent($this->handle, $transparency);
         }
     }
     $imgProperties = self::getImageFileProperties($this->getPath());
     if ($imgProperties->mime == MIME_GIF) {
         $trnprt_indx = imagecolortransparent($this->handle);
         if ($trnprt_indx >= 0 && $trnprt_indx < imagecolorstotal($this->handle)) {
             $trnprt_color = imagecolorsforindex($this->handle, $trnprt_indx);
             $trnprt_indx = imagecolorallocate($handle, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']);
             imagefill($handle, 0, 0, $trnprt_indx);
             imagecolortransparent($handle, $trnprt_indx);
         }
     } elseif ($imgProperties->mime == MIME_PNG) {
         imagealphablending($handle, false);
         imagesavealpha($handle, true);
         if ($this->isTransparent()) {
             $transparent = imagecolorallocatealpha($this->handle, 255, 255, 255, 127);
             imagefilledrectangle($this->handle, 0, 0, $width, $height, $transparent);
         }
     }
     if ($this->isTransparent()) {
         $trnprt_indx = imagecolortransparent($this->handle);
         if ($trnprt_indx >= 0 && $trnprt_indx < imagecolorstotal($this->handle)) {
             // Get the transparent color values for the current image.
             $rgba = imageColorsForIndex($this->handle, imagecolortransparent($this->handle));
             $color = imageColorAllocateAlpha($handle, $rgba['red'], $rgba['green'], $rgba['blue'], $rgba['alpha']);
         } else {
             $color = imageColorAllocateAlpha($handle, 255, 255, 255, 127);
         }
         // Set the transparent color values for the new image.
         imagecolortransparent($handle, $color);
         imagefill($handle, 0, 0, $color);
         imagecopyresized($handle, $this->handle, $offset->x, $offset->y, 0, 0, $dimensions->width, $dimensions->height, $this->getWidth(), $this->getHeight());
     } else {
         call_user_func_array($resizemethod, array(&$handle, &$this->handle, $offset->x, $offset->y, 0, 0, $dimensions->width, $dimensions->height, $this->getWidth(), $this->getHeight()));
     }
     // If we are resizing to a new image, create a new KunenaImage object.
     if ($createNew) {
         // @codeCoverageIgnoreStart
         $new = new KunenaImage($handle);
         return $new;
         // @codeCoverageIgnoreEnd
     } else {
         // Free the memory from the current handle
         $this->destroy();
         $this->handle = $handle;
         return $this;
     }
 }