imagick icon indicating copy to clipboard operation
imagick copied to clipboard

investigate HSL colorspace shenanigans.

Open Danack opened this issue 4 years ago • 0 comments

output_gradient_after_brightness_HSL

<?php

declare(strict_types=1);

$colorspaces = [
	"LOG" => Imagick::COLORSPACE_LOG,
	"HSL" => Imagick::COLORSPACE_HSL,
	"RGB" => Imagick::COLORSPACE_RGB,
	"SRGB" => Imagick::COLORSPACE_SRGB,
];


foreach ($colorspaces as $name => $colorspace) {

	echo "Colorspace $name\n";

	$imagick = new Imagick();

	$export_type = Imagick::PIXEL_FLOAT;
	$digits = 4;

	$brightness = 188;
//	$brightness = 144;
	$hue = 145.0;

//	$imagick->setColorspace($colorspace); // comment this in
	$imagick->newPseudoImage(100, 100, "gradient:rgb(255,0,0)-rgb(128,255,255)");
	$imagick->writeImage(__DIR__ . "/gradient/output_gradient_$name.png");
	$imagick->transformImageColorspace($colorspace); // comment this out

	$step_0_values = $imagick->exportImagePixels(
		0,
		1,
		100,
		1,
		"RGB",
		$export_type
	);


	$imagick->modulateImage($brightness, 100, 100);
	$imagick2 = clone $imagick;
	$imagick2->transformImageColorspace(Imagick::COLORSPACE_SRGB);
	$imagick2->writeImage(__DIR__ . "/gradient/output_gradient_after_brightness_$name.png");


	$step_1_values = $imagick->exportImagePixels(
		0,
		1,
		100,
		1,
		"RGB",
		$export_type
	);

	$imagick->modulateImage(100.0, $hue, 100.);

	$imagick2 = clone $imagick;
	$imagick2->transformImageColorspace(Imagick::COLORSPACE_SRGB);
	$imagick2->writeImage(__DIR__ . "/gradient/output_gradient_after_saturation_$name.png");
	$step_2_values = $imagick->exportImagePixels(
		0,
		1,
		100,
		1,
		"RGB",
		$export_type
	);

	$step_3_values = $imagick->exportImagePixels(
		0,
		1,
		100,
		1,
		"RGB",
		$export_type
	);


	echo "Start, after brightness, after hue \n";

	for ($i = 95; $i < 100; $i += 1) {
		$r_0 = $step_0_values[(3 * $i)];
		$g_0 = $step_0_values[(3 * $i) + 1];
		$b_0 = $step_0_values[(3 * $i) + 2];

		$r_1 = $step_1_values[(3 * $i)];
		$g_1 = $step_1_values[(3 * $i) + 1];
		$b_1 = $step_1_values[(3 * $i) + 2];

		$r_2 = $step_2_values[(3 * $i)];
		$g_2 = $step_2_values[(3 * $i) + 1];
		$b_2 = $step_2_values[(3 * $i) + 2];

		$format = "rgb(%$digits.2f, %$digits.2f, %$digits.2f)";
		$format_string = "%2d  $format, $format, $format\n";

		printf(
			$format_string,
			$i,
			$r_0, $g_0, $b_0,
			$r_1, $g_1

, $b_1,
			$r_2, $g_2, $b_2
		);
	}
}

Danack avatar Dec 01 '21 17:12 Danack