1

Here is the code that I am using currently.

$image = imagecreatetruecolor(400, 300);
imagesavealpha($image, true);
imagesetthickness($image, 2);

$red = imagecolorallocate($image, 255, 0, 0);
$green = imagecolorallocate($image, 0, 255, 0);
$blue = imagecolorallocate($image, 0, 0, 255);
$transparent = imagecolorallocatealpha($image, 255, 255, 255, 0);

imagefill($image, 0, 0, $transparent);

imagerectangle($image, 2, 2, 398, 298, $red);
imagedashedline($image, 0, 150, 400, 150, $blue);
imagedashedline($image, 200, 0, 200, 300, $blue);
imagepolygon($image, array( 10, 180, 10, 250, 110, 250), 3, $red);

// imageflip($image, IMG_FLIP_VERTICAL);

ob_start();
imagepng($image);
printf('<img src="data:image/png;base64,%s"/>', base64_encode(ob_get_clean()));

imagedestroy($image);

The attached image is result of running the above code.

I want to flip the triangle in the bottom right corner and draw it along with the original image. I tried to use imageflip() but it draws over the original image.

I know that imageflip() is flipping the rectangle as well as dotted lines but they are symmetric so it is no big deal.

Setting the fill color to transparent did not work. Any help would be appreciated.

My aim is to take original image, flip it along the horizontal line and then flip the resulting image along vertical line.

Once I know how to flip along the horizontal line without loosing the original image, I can try to do the rest on my own.

enter image description here

iKnowNothing
  • 175
  • 11

2 Answers2

0

if you want you can use javascript if you know it to get the style of it then add a new one but that can be complicated. I can walk you through it, although that will take quite a bit of time. I can help if you have a github

Nick
  • 69
  • 5
  • Actually I was conflicted between using JavaScript canvas API or PHP GD. Do you think such things would be easier in JavaScript? – iKnowNothing May 26 '18 at 02:38
  • you will definitely want php inside your code but javascritp is not a bad way to go. and yes, it would definitely be easier to use document.getElementById than anything else in my opinion. – Nick May 26 '18 at 02:44
0

If you want to preserve original image before flip, then use imagecopy() to duplicate image then call imageflip() using new duplicate image.

$flipImage = imagecreatetruecolor(400, 300);
imagecopy($flipImage, $image, 0, 0, 0, 0, 400, 300);
imageflip($flipImage, IMG_FLIP_HORIZONTAL);
Zamrony P. Juhara
  • 5,222
  • 2
  • 24
  • 40