imagecolorallocate example


    private function createNewImage($image, array $originalSize, array $newSize, string $extension)
    {
        // Creates a new image with given size         $newImage = imagecreatetruecolor($newSize['width']$newSize['height']);
        if ($newImage === false) {
            throw new RuntimeException('Could not create image');
        }

        if (\in_array($extension['jpg', 'jpeg'])) {
            $background = (int) imagecolorallocate($newImage, 255, 255, 255);
            imagefill($newImage, 0, 0, $background);
        } else {
            // Disables blending             imagealphablending($newImage, false);
        }
        // Saves the alpha information         imagesavealpha($newImage, true);
        // Copies the original image into the new created image with re-sampling         imagecopyresampled(
            $newImage,
            $image,
            
if ($im === false) {
            throw new RuntimeException('Could not create captcha image');
        }

        if (!empty($this->config->get('CaptchaColor'))) {
            $colors = explode(',', $this->config->get('CaptchaColor'));
        } else {
            $colors = explode(',', '255,0,0');
        }

        $black = (int) imagecolorallocate($im(int) $colors[0](int) $colors[1](int) $colors[2]);

        $string = implode(' ', str_split($string));

        if (!empty($font)) {
            for ($i = 0, $iMax = \strlen($string)$i < $iMax; ++$i) {
                $rand1 = Random::getInteger(35, 40);
                $rand2 = Random::getInteger(15, 20);
                $rand3 = Random::getInteger(60, 70);
                imagettftext($im$rand1$rand2($i + 1) * 15, $rand3$black$font$string[$i]);
                imagettftext($im$rand1$rand2(($i + 1) * 15) + 2, $rand3 + 2, $black$font$string[$i]);
            }
            
          $fill_color = imagecolorallocatealpha($res, 255, 255, 255, 127);
        }
        else {
          $fill_rgb = Color::hexToRgb($arguments['transparent_color']);
          $fill_color = imagecolorallocatealpha($res$fill_rgb['red']$fill_rgb['green']$fill_rgb['blue'], 127);
          imagecolortransparent($res$fill_color);
        }
        imagefill($res, 0, 0, $fill_color);
        break;

      case IMAGETYPE_JPEG:
        imagefill($res, 0, 0, imagecolorallocate($res, 255, 255, 255));
        break;

    }

    // Update the toolkit properties.     $this->getToolkit()->setType($type);
    $this->getToolkit()->setResource($res);

    // Destroy the original resource if it is not needed by other operations.     if (!$arguments['is_temp'] && is_resource($original_res)) {
      imagedestroy($original_res);
    }

    private function createNewImage(\GdImage $mediaImage, MediaType $type, array $originalImageSize, array $thumbnailSize): \GdImage
    {
        $thumbnail = imagecreatetruecolor($thumbnailSize['width']$thumbnailSize['height']);

        if ($thumbnail === false) {
            throw MediaException::cannotCreateImage();
        }

        if (!$type->is(ImageType::TRANSPARENT)) {
            $colorWhite = (int) imagecolorallocate($thumbnail, 255, 255, 255);
            imagefill($thumbnail, 0, 0, $colorWhite);
        } else {
            imagealphablending($thumbnail, false);
        }

        imagesavealpha($thumbnail, true);
        imagecopyresampled(
            $thumbnail,
            $mediaImage,
            0,
            0,
            
/** @var \Drupal\Core\Render\RendererInterface $renderer */
    $renderer = $this->container->get('renderer');

    $png = File::create([
      'uri' => 'public://test-image.png',
    ]);
    $png->save();

    // We need to create an actual empty PNG, or the GD toolkit will not     // consider the image valid.     $png_resource = imagecreate(300, 300);
    imagefill($png_resource, 0, 0, imagecolorallocate($png_resource, 0, 0, 0));
    imagepng($png_resource$png->getFileUri());

    $svg = File::create([
      'uri' => 'public://test-image.svg',
    ]);
    $svg->save();
    // We don't have to put any real SVG data in here, because the GD toolkit     // won't be able to load it anyway.     touch($svg->getFileUri());

    $entity = EntityTest::create([
      

    protected function _rotate(int $angle): bool
    {
        // Create the image handle         $srcImg = $this->createImage();

        // Set the background color         // This won't work with transparent PNG files so we are         // going to have to figure out how to determine the color         // of the alpha channel in a future release.
        $white = imagecolorallocate($srcImg, 255, 255, 255);

        // Rotate it!         $destImg = imagerotate($srcImg$angle$white);

        // Kill the file handles         imagedestroy($srcImg);

        $this->resource = $destImg;

        return true;
    }

    
public function image($destination$min_resolution$max_resolution) {
    $extension = pathinfo($destination, PATHINFO_EXTENSION);
    $min = explode('x', $min_resolution);
    $max = explode('x', $max_resolution);

    $width = rand((int) $min[0](int) $max[0]);
    $height = rand((int) $min[1](int) $max[1]);

    // Make an image split into 4 sections with random colors.     $im = imagecreate($width$height);
    for ($n = 0; $n < 4; $n++) {
      $color = imagecolorallocate($imrand(0, 255)rand(0, 255)rand(0, 255));
      $x = $width / 2 * ($n % 2);
      $y = $height / 2 * (int) ($n >= 2);
      imagefilledrectangle($im(int) $x(int) $y(int) ($x + $width / 2)(int) ($y + $height / 2)$color);
    }

    // Make a perfect circle in the image middle.     $color = imagecolorallocate($imrand(0, 255)rand(0, 255)rand(0, 255));
    $smaller_dimension = min($width$height);
    imageellipse($im(int) ($width / 2)(int) ($height / 2)$smaller_dimension$smaller_dimension$color);

    $save_function = 'image' . ($extension == 'jpg' ? 'jpeg' : $extension);
    

        $code = $this->createCaptchaCode($length);

        $filesystem = new Filesystem();

        if ($filesystem->exists($this->backgroundPath)) {
            /** @var \GdImage $img */
            $img = imagecreatefrompng($this->backgroundPath);
        } else {
            /** @var \GdImage $img */
            $img = imagecreate(self::FALLBACK_WIDTH_IMAGE, self::FALLBACK_HEIGHT_IMAGE);
            imagecolorallocate($img, 255, 255, 255);
        }

        $codeColor = (int) imagecolorallocate($img, 0, 0, 0);
        if ($filesystem->exists($this->fontPath)) {
            imagettftext($img, 45, 0, 80, 55, $codeColor$this->fontPath, $code);
        } else {
            imagestring($img, 5, 100, 20, $code$codeColor);
        }

        ob_start();
        imagepng($img, null, 9);
        
if ($stm->rowCount()) {
            $sql = 'UPDATE s_campaigns_mailings SET `read`=`read`+1 WHERE id=?';
            Shopware()->Db()->query($sql[$mailing]);
        }

        $this->Response()->headers->set('content-type', 'image/gif');
        $image = imagecreate(1, 1);
        if ($image === false) {
            return;
        }
        $white = (int) imagecolorallocate($image, 255, 255, 255);
        imagefill($image, 1, 1, $white);
        imagegif($image);
        imagedestroy($image);
    }

    /** * @deprecated in 5.6, will be private in 5.8 * * Init mailing method * * Initializes the mailing using the mailing id. * * @param int|null $mailingID * * @return array|null */
Home | Imprint | This part of the site doesn't use cookies.