Jump to content

Marking black points


MaxDJs

Recommended Posts

I have a picture (attached), where I find the coordinates of black points, because I do not remember any point, so you want every point at which I find coordinates with mark a red cross as watermark.

 

At the coordinates using this script:

<?php

if(isset($_GET["obrazek_x"]))

  file_put_contents("soubor.txt",$_GET["obrazek_x"].",".$_GET["obrazek_y"]."\n",FILE_APPEND);

?> 

 

Coordinates I save to an external file in this format:

 

602;744

 

Could you advise me a solution to mark black points?

 

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/222064-marking-black-points/
Share on other sites

It is not homework!

 

It occurred to me to use a watermark, but I do not know if:

 

1) can be multiple watermarks in one image or only one watermark.

 

2) I can determine the position of the watermark, or if it fixed the lower right corner.

 

I need advice on how to convert an external file (attached) into the PHP array.

 

 

 

[attachment deleted by admin]

early Saturday rambling psuedo code (presumes 1. coords are center point of Blackened, 2. red x image is 20 x 20 ---- make necessary adjustments)...

<?PHP
$file_name = "coord.txt '; /* this is the file that contains your coordinates */
$lines = file($file_name); /* read the file into an array */
$ne = count($lines); /* count the number of coordinate pairs */
$i = 0; /* set your initial counter */
while($i<$ne) { /* start looping thru the pairs */
$coords = explode(",", $lines[$i]); /* get the coords of the each element */
$x = $coords[0] - 10; /* calculate upper left point */
$y = $coords[1] - 10;
/* if $i = open your template image else open the saved image */
/* use a watermark script to overlay an X at the points calculated above */
/* save the image */
$i ++;
}

I already have a script, but when I start it, so it suits me the error 500 Internal Server Error

Here is the script:

 

<?php
$file_name = "soubor.txt"; /* this is the file that contains your coordinates */
$lines = file($file_name); /* read the file into an array */
$ne = count($lines); /* count the number of coordinate pairs */
$i = 0; /* set your initial counter */
$image = imagecreatefromjpeg('sál.jpg');
$w = imagesx($image);
$h = imagesy($image);
$watermark = imagecreatefromjpeg('krizek.jpeg');
$ww = imagesx($watermark);
$wh = imagesy($watermark);

while($i<$ne) { /* start looping thru the pairs */
$coords = explode(",", $lines[$i]); /* get the coords of the each element */
$x = $coords[0] - 10; /* calculate upper left point */
$y = $coords[1] - 10;
imagecopy($image, $watermark, $x, $y, 0, 0, $ww, $wh);
header('Content-type: image/jpeg');
imagejpeg($image);
exit();    
$i ++;
}

?>

Ok - I am NOT an expert; however, this does work. It places a red X at the coords in your file ON your image. It loops thru all the coords and places the X at each point.

 

You NEED to make whatever adjustments for font, color, precise location. IF your template image changes it WILL effect the location of your X's.

 

Really this is just a 'proof of concept' to show how it might be done.

 

Hope it helps.

<?php
function watermarkImage($SourceFile, $WaterMarkText, $DestinationFile, $x, $y) {
   list($width, $height) = getimagesize($SourceFile);
   $image_p = imagecreatetruecolor($width, $height);
   $image = imagecreatefromjpeg($SourceFile);
   imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width, $height);
   $black = imagecolorallocate($image_p, 255, 0, 0);
   $font = 'arial.ttf';
   $font_size = 50;
   imagettftext($image_p, $font_size, 0, $x, $y, $black, $font, $WaterMarkText);
   if ($DestinationFile<>'') {
      imagejpeg ($image_p, $DestinationFile, 100);
   } else {
      header('Content-Type: image/jpeg');
      imagejpeg($image_p, null, 100);
   }
   imagedestroy($image);
   imagedestroy($image_p);
}
$WaterMarkText = "X";
$DestinationFile = "finished.jpg";


$file_name = "soubor.txt"; /* this is the file that contains your coordinates */
$lines = file($file_name); /* read the file into an array */
$ne = count($lines); /* count the number of coordinate pairs */
$i = 0; /* set your initial counter */

while($i<$ne) { /* start looping thru the pairs */
$coords = explode(",", $lines[$i]); /* get the coords of the each element */
if($i <1) {
	$SourceFile = "template.jpg";
}else{
	$SourceFile = "finished.jpg";
}
$x = $coords[0]; /* calculate left corner point */
$y = $coords[1]; /* calculate upper corner point */
watermarkImage($SourceFile, $WaterMarkText, $DestinationFile, $x, $y);
$i ++;
}
?>
<img src="finished.jpg" alt="">
<?PHP

?>

 

here is the script in action http://nstoia.com/projects/wm/

Tested the code out, didnt get a 500 internal server error

 

Just moved 3 lines out of the loop, worked fine

<?php
$file_name = "soubor.txt"; /* this is the file that contains your coordinates */
$lines = file($file_name); /* read the file into an array */
$ne = count($lines); /* count the number of coordinate pairs */
$i = 0; /* set your initial counter */
$image = imagecreatefromjpeg('sal.jpg');
$w = imagesx($image);
$h = imagesy($image);
$watermark = imagecreatefromgif('checkmark.gif');
$ww = imagesx($watermark);
$wh = imagesy($watermark);

while($i<$ne) { /* start looping thru the pairs */
$coords = explode(",", $lines[$i]); /* get the coords of the each element */
$x = $coords[0] - 10; /* calculate upper left point */
$y = $coords[1] - 10;
imagecopy($image, $watermark, $x, $y, 0, 0, $ww, $wh);
$i ++;
}
header('Content-type: image/jpeg');
imagejpeg($image);
exit();    

 

changed the watermark from jpeg to gif so as to have a transparency.

 

 

 

[attachment deleted by admin]

It don't work. Give it the address of the script

In my case:

http://localhost/odchyceni_pozice_sedadel/oznacena_sedadla.php

 

<?php
$file_name = "soubor.txt"; /* this is the file that contains your coordinates */
$lines = file($file_name); /* read the file into an array */
$ne = count($lines); /* count the number of coordinate pairs */
$i = 0; /* set your initial counter */
$image = imagecreatefromjpeg('sal.jpg');
$w = imagesx($image);
$h = imagesy($image);
$watermark = imagecreatefromgif('checkmark.gif');
$ww = imagesx($watermark);
$wh = imagesy($watermark);

while($i<$ne) { /* start looping thru the pairs */
$coords = explode(",", $lines[$i]); /* get the coords of the each element */
$x = $coords[0] - 10; /* calculate upper left point */
$y = $coords[1] - 10;
imagecopy($image, $watermark, $x, $y, 0, 0, $ww, $wh);
$i ++;
}
header('Content-type: image/jpeg');
imagejpeg($image);
exit();    
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.