Jump to content

Recommended Posts

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.