<commit_before><?php

namespace A6digital\Image;

use Illuminate\Support\Str;
use Intervention\Image\ImageManagerStatic;
use Exception;

class DefaultProfileImage
{

	/**
	 * @param string $name
	 * @param int $size
	 * @return ImageManagerStatic
	 * @throws Exception
	 */
	public static function create ($name = '', $size = 512, $background_color = '#666', $text_color = '#FFF')
	{
	
		if (strlen($name) <= 0) {
			throw new Exception('Name must be at least 2 characters.');
		}
		
		if ($size <= 0) {
			throw new Exception('Input must be greater than zero.');
		}

		$str = "";
		$name_ascii = strtoupper(Str::ascii($name));

		$words = preg_split("/[\s,_-]+/", $name_ascii);
		if(count($words) >= 2) $str = $words[0][0].$words[1][0];
		else $str = substr($name_ascii, 0, 2);

		$img = ImageManagerStatic::canvas($size, $size, $background_color)->text($str, $size / 2, $size / 2, function($font) use($size, $text_color) {
			$font->file((__DIR__.'/../../../font/OpenSans-Semibold.ttf'));
			$font->size($size / 2);
			$font->color($text_color);
			$font->align('center');
			$font->valign('middle');
		});
		
		return $img;
		
	}

}<commit_msg>Added ability for custom fonts<commit_after><?php

namespace A6digital\Image;

use Illuminate\Support\Str;
use Intervention\Image\ImageManagerStatic;
use Exception;

class DefaultProfileImage
{

	/**
	 * @param string $name
	 * @param int $size
	 * @return ImageManagerStatic
	 * @throws Exception
	 */
	public static function create ($name = '', $size = 512, $background_color = '#666', $text_color = '#FFF', $font_file = '../../../font/OpenSans-Semibold.ttf')
	{
	
		if (strlen($name) <= 0) {
			throw new Exception('Name must be at least 2 characters.');
		}
		
		if ($size <= 0) {
			throw new Exception('Input must be greater than zero.');
		}

        if ($font_file === '../../../font/OpenSans-Semibold.ttf') {
            $font_file = __DIR__."/".$font_file;
        }

        if (!file_exists($font_file)) {
            throw new Exception("Font file not found");
        }

		$str = "";
		$name_ascii = strtoupper(Str::ascii($name));

		$words = preg_split("/[\s,_-]+/", $name_ascii);
		if(count($words) >= 2) $str = $words[0][0].$words[1][0];
		else $str = substr($name_ascii, 0, 2);

		$img = ImageManagerStatic::canvas($size, $size, $background_color)->text($str, $size / 2, $size / 2, function($font) use($size, $text_color, $font_file) {
			$font->file($font_file);
			$font->size($size / 2);
			$font->color($text_color);
			$font->align('center');
			$font->valign('middle');
		});
		
		return $img;
		
	}

}
{'fraction_non_alphanumeric': 0.19968919968919968, 'fraction_numerical': 0.01554001554001554, 'mean_word_length': 3.493891797556719, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1876654', 'n_tokens_mistral': 1001, 'n_tokens_neox': 882, 'n_words': 198}