Generator::image_center( GdImage|false $image, string $text, string $font, string $size, integer $angle = 8 )

Description #

Get center position on image.

Parameters #

  • $image
    GdImage | false (Required) Image resource.
  • $text
    string (Required) Text.
  • $font
    string (Required) Font file path.
  • $size
    string (Required) Size of image.
  • $angle
    integer (Optional) Angle. Default value: 8

Source #

File: addons/avatar/class-generator.php

	protected function image_center( $image, $text, $font, $size, $angle = 8 ) {
		$xi  = imagesx( $image );
		$yi  = imagesy( $image );
		$box = imagettfbbox( $size, $angle, $font, $text );
		$xr  = abs( max( $box[2], $box[4] ) );
		$yr  = abs( max( $box[5], $box[7] ) );
		$x   = intval( ( $xi - $xr ) / 2 );
		$y   = intval( ( $yi + $yr ) / 2 );

		return array( $x, $y );
	}

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