imagecreate example


  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);

    
public function generate(int $length = 7): BasicCaptchaImage
    {
        $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();
        
/** @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());

    

        $stm = Shopware()->Db()->query($sql[$mailing$email]);

        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.