image — Создание эллипса с помощью переполнения стека

Мне нужно создать эллипс, как показано ниже, с пользовательскими цветами.

Пользовательское изображение

я использую Изображение вмешательства библиотека для достижения этого.

Что я сделал, это:
Я создал 6 разных прозрачных изображений для каждого раздела.
И пытается создать холст, а затем маскировать другой слой на нем, но результат не такой, как ожидалось.
Благодаря этому процессу я могу раскрасить только первый участок изображения.

    Image::configure(array('driver' => 'gd'));
$img = Image::canvas(150,104,'#000')->insert(WWW_ROOT.DS.IMAGES_URL.'test/masks/1.png');
$img->mask(WWW_ROOT.DS.IMAGES_URL.'test/masks/2.png', true);
$img->mask(WWW_ROOT.DS.IMAGES_URL.'test/masks/3.png', true);
$img->mask(WWW_ROOT.DS.IMAGES_URL.'test/masks/4.png', true);
$img->mask(WWW_ROOT.DS.IMAGES_URL.'test/masks/5.png', true);
$img->mask(WWW_ROOT.DS.IMAGES_URL.'test/masks/6.png', true);
$img->save(WWW_ROOT.DS.IMAGES_URL.'test/test.png');
echo $img->response();

Мне нужна помощь, чтобы создать вышеупомянутое изображение Custom Color или любые другие варианты для достижения этой цели.

1

Решение

Не идеально, но лучше

<?php
$image = imagecreatetruecolor(300, 300);$white    = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
$gray     = imagecolorallocate($image, 0xC0, 0xC0, 0xC0);
$darkgray = imagecolorallocate($image, 0x90, 0x90, 0x90);
$navy     = imagecolorallocate($image, 0x00, 0x00, 0x80);
$darknavy = imagecolorallocate($image, 0x00, 0x00, 0x50);
$red      = imagecolorallocate($image, 0xFF, 0x00, 0x00);
$darkred  = imagecolorallocate($image, 0x90, 0x00, 0x00);
$white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);for ($i = 60; $i > 50; $i--) {
imagefilledarc($image, 150, $i, 300, 50, 0, 60, $darknavy, IMG_ARC_PIE);
imagefilledarc($image, 150, $i, 300, 50, 60, 120 , $darkgray, IMG_ARC_PIE);
imagefilledarc($image, 150, $i, 300, 50, 120, 180 , $darkred, IMG_ARC_PIE);

imagefilledarc($image, 150, $i, 300, 50, 180, 240 , $navy, IMG_ARC_PIE);
imagefilledarc($image, 150, $i, 300, 50, 240, 270 , $gray, IMG_ARC_PIE);
imagefilledarc($image, 150, $i, 300, 50, 270, 360 , $red, IMG_ARC_PIE);}

imagefilledarc($image, 150, 50, 300, 50, 0, 60, $navy, IMG_ARC_PIE);
imagefilledarc($image, 150, 50, 300, 50, 60, 120 , $gray, IMG_ARC_PIE);
imagefilledarc($image, 150, 50, 300, 50, 120, 180 , $red, IMG_ARC_PIE);

imagefilledarc($image, 150, 50, 300, 50, 180, 240 , $navy, IMG_ARC_PIE);
imagefilledarc($image, 150, 50, 300, 50, 240, 270 , $gray, IMG_ARC_PIE);
imagefilledarc($image, 150, 50, 300, 50, 270, 360 , $red, IMG_ARC_PIE);

imagefilledarc($image, 150, 50, 280, 40, 0, 360, $white, IMG_ARC_PIE);header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
?>
1

Другие решения

Почему бы не использовать imageellipse(), imagefilledellipse() а также imagefilledarc() ?

<?php

// Création de l'image
$image = imagecreatetruecolor(100, 100);

// Allocation de quelques couleurs
$white    = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
$gray     = imagecolorallocate($image, 0xC0, 0xC0, 0xC0);
$darkgray = imagecolorallocate($image, 0x90, 0x90, 0x90);
$navy     = imagecolorallocate($image, 0x00, 0x00, 0x80);
$darknavy = imagecolorallocate($image, 0x00, 0x00, 0x50);
$red      = imagecolorallocate($image, 0xFF, 0x00, 0x00);
$darkred  = imagecolorallocate($image, 0x90, 0x00, 0x00);

// Création de l'effet 3D
for ($i = 60; $i > 50; $i--) {
imagefilledarc($image, 50, $i, 100, 50, 0, 45, $darknavy, IMG_ARC_PIE);
imagefilledarc($image, 50, $i, 100, 50, 45, 75 , $darkgray, IMG_ARC_PIE);
imagefilledarc($image, 50, $i, 100, 50, 75, 360 , $darkred, IMG_ARC_PIE);
}

imagefilledarc($image, 50, 50, 100, 50, 0, 45, $navy, IMG_ARC_PIE);
imagefilledarc($image, 50, 50, 100, 50, 45, 75 , $gray, IMG_ARC_PIE);
imagefilledarc($image, 50, 50, 100, 50, 75, 360 , $red, IMG_ARC_PIE);// Affichage de l'image
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
?>
0

Наконец-то я смог достичь желаемого результата.

Что я сделал, это:

Использовал это образ чтобы получить координаты полигона каждой области через это библиотека jQuery.

После получения координат для каждого региона я создал желаемое изображение, используя многоугольник функция предоставлена Библиотека изображений вмешательства.

Спасибо всем за вашу помощь, может быть, это может помочь кому-то еще.

0
По вопросам рекламы ammmcru@yandex.ru
Adblock
detector