AnsPress_Avatar::image_gradientrect( resource $img, string $start, string $end )

Description #

Fill gradient.

Parameters #

  • $img
    resource (Required) Image resource.
  • $start
    string (Required) Start color.
  • $end
    string (Required) End color.

Source #

File: addons/free/avatar.php

	private function image_gradientrect( $img, $start, $end ) {
		$x = 0;
		$y = 0;
		$x1 = 90;
		$y1 = 90;

		if ( $x > $x1 || $y > $y1 ) {
			return false;
		}

		$start = str_replace( '#', '', $start );
		$end = str_replace( '#', '', $end );

		$s = array(
			hexdec( substr( $start, 0, 2 ) ),
			hexdec( substr( $start, 2, 2 ) ),
			hexdec( substr( $start, 4, 2 ) ),
		);

		$e = array(
			hexdec( substr( $end, 0, 2 ) ),
			hexdec( substr( $end, 2, 2 ) ),
			hexdec( substr( $end, 4, 2 ) ),
		);

		$steps = $y1 - $y;
		for ( $i = 0; $i < $steps; $i++ ) {
			$r = $s[0] - ( ( ( $s[0] - $e[0] ) / $steps ) * $i );
			$g = $s[1] - ( ( ( $s[1] - $e[1] ) / $steps ) * $i );
			$b = $s[2] - ( ( ( $s[2] - $e[2]) / $steps ) * $i );
			$color = imagecolorallocate( $img, $r, $g, $b );
			imagefilledrectangle( $img, $x, $y + $i, $x1, $y + $i + 1, $color );
		}

		return true;
	}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment