Thomisback Posted January 16, 2009 Share Posted January 16, 2009 Hi, I have a very complex image editing problem, I've been trying to get this to work for 2 days now so I decided to post it over here. What I'm trying to do is: - Extract numbers from an image and save them into separate files, coordinates of where the image has to be cut are known - Background is always white - Numbers are always black An array contains the X-values where the image has to be cut: Array ( [0] => 8 [1] => 18 [2] => 40 [3] => 45 [4] => 55 [5] => 83 [6] => 92 [7] => 113 [8] => 120 [9] => 130 ) Now I tried to cut the image using this code: $filename = 'image.jpg'; // Resample $image_p = imagecreatetruecolor(($lines[0]), $totalY); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $x, $y, $x, $y); // Output imagejpeg($image_p,"1.jpg",100); exec("convert 1.jpg -fuzz 2% -trim 1.jpg"); $white = imagecolorallocate($image, 255, 255, 255); for($xx = 0; $xx <= $lines[0]; $xx++){ for($yy = 0; $yy <= imagesy($image); $yy++){ $currentCount++; imagesetpixel($image, round($xx),round($yy), $white); // echo "X = $x and Y = $y<br>"; } } imagejpeg($image, 'image.jpg', 100); // exec("convert image.jpg -fuzz 2% -trim image.jpg"); //trim border down $lines = array_slice($lines, 1); $lines represents an array containing all the X-coordinates. The code I tried above is very buggy and isn't reliable, does anyone know a way to do this which would be better? Kind regards, your help is appreciated. Link to comment https://forums.phpfreaks.com/topic/141098-solved-complicated-image-problem/ Share on other sites More sharing options...
Thomisback Posted January 17, 2009 Author Share Posted January 17, 2009 Anyone? Link to comment https://forums.phpfreaks.com/topic/141098-solved-complicated-image-problem/#findComment-738923 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.