44
55namespace Tamedevelopers \Support \Commands ;
66
7+ use Tamedevelopers \Support \Tame ;
78use Tamedevelopers \Support \Server ;
89use Tamedevelopers \Support \ImageToText ;
910use Tamedevelopers \Support \NameToImage ;
11+ use Tamedevelopers \Support \Capsule \File ;
1012use Tamedevelopers \Support \Capsule \Logger ;
1113use Tamedevelopers \Support \Capsule \CommandHelper ;
1214
@@ -36,8 +38,8 @@ class ProcessorCommand extends CommandHelper
3638 public function handle ()
3739 {
3840 Logger::helpHeader ('<yellow>Usage:</yellow> ' );
39- Logger::writeln (' php tame make: processor [ name] ' );
40- Logger::writeln (' php tame make: processor [name ] ' );
41+ Logger::writeln (" php tame processor:toImage -- name --path --bgColor --textColor --fontWeight=[bold|normal] --type=[circle|radius] --generate=[bool] \n" );
42+ Logger::writeln (' php tame processor:toText --path= --grayscale=[bool] --contrast=[int ] ' );
4143 Logger::writeln ('' );
4244 }
4345
@@ -46,15 +48,15 @@ public function handle()
4648 */
4749 public function toImage (): string
4850 {
49- $ args = $ this ->arguments ();
50- [$ name , $ bgColor , $ textColor , $ path , $ generate , $ output , $ fontWeight ] = [
51+ [$ name , $ bgColor , $ textColor , $ path , $ generate , $ output , $ fontWeight , $ type ] = [
5152 $ this ->flag ('name ' ),
5253 $ this ->flag ('bgColor ' ),
5354 $ this ->flag ('textColor ' ),
5455 $ this ->flag ('path ' ),
55- $ this ->flag ('output ' ),
5656 (bool ) $ this ->flag ('generate ' ) ?: false ,
57+ $ this ->flag ('output ' ),
5758 $ this ->flag ('fontWeight ' ),
59+ $ this ->flag ('type ' ),
5860 ];
5961
6062 if (!in_array ($ output , ['save ' , 'data ' ])){
@@ -69,46 +71,38 @@ public function toImage(): string
6971 'destination ' => $ path ,
7072 'output ' => $ output ,
7173 'generate ' => $ generate ,
74+ 'type ' => $ type ,
7275 ]));
7376
77+ $ path = Tame::getBasePath ($ path );
78+
7479 Logger::info ("$ path \n" );
7580
7681 return $ path ;
7782 }
7883
7984 /**
80- * Convert and Extract Image to Text
85+ * Extract an Image to Text
8186 */
8287 public function toText (): string
8388 {
84- $ args = $ this ->arguments ();
85- [$ name , $ bgColor , $ textColor , $ path , $ generate , $ output , $ fontWeight ] = [
86- $ this ->flag ('name ' ),
87- $ this ->flag ('bgColor ' ),
88- $ this ->flag ('textColor ' ),
89- $ this ->flag ('path ' ),
90- $ this ->flag ('output ' ),
91- (bool ) $ this ->flag ('generate ' ) ?: false ,
92- $ this ->flag ('fontWeight ' ),
89+ [$ path , $ grayscale , $ contrast ] = [
90+ $ this ->flag ('path ' ),
91+ (bool ) $ this ->flag ('grayscale ' ) ?: true ,
92+ $ this ->flag ('contrast ' ) ?: 20 ,
9393 ];
94-
95- if (!in_array ($ output , ['save ' , 'data ' ])){
96- $ output = 'save ' ;
97- }
98-
99- $ path = Server::pathReplacer (ImageToText::run ([
100- 'name ' => $ name ,
101- 'bg_color ' => $ bgColor ,
102- 'font_weight ' => $ fontWeight ,
103- 'text_color ' => $ textColor ,
104- 'destination ' => $ path ,
105- 'output ' => $ output ,
106- 'generate ' => $ generate ,
107- ]));
108-
109- Logger::info ("$ path \n" );
110-
111- return $ path ;
94+
95+ $ text = ImageToText::run ([
96+ 'source ' => Tame::getBasePath ($ path ),
97+ 'preprocess ' => [
98+ 'grayscale ' => $ grayscale ,
99+ 'contrast ' => $ contrast ,
100+ ],
101+ ]);
102+
103+ Logger::info ("$ text \n" );
104+
105+ return $ text ;
112106 }
113107
114108}
0 commit comments