Jump to content

GD Library, it is possible?


lopes_andre

Recommended Posts

Thanks for the reply,

 

I'am testing this code, but it is not working...

 

<?php
   $img = imagecreatefromjpeg("image2.jpg");
  
   $w = imagesx($img);
   $h = imagesy($img);
  
   for($y=0;$y<$h;$y++) {
      for($x=0;$x<$w;$x++) {
         $rgb = imagecolorat($img, $x, $y);        
         imagecolorset($img, $rgb, 0, 0, 255);
      }
   }
?>

 

Any clue?

 

Best Regards,

Link to comment
Share on other sites

That code will loop through every color and change that color to blue. Making the entire image blue. Try something like:

 

$img = imagecreatefromjpeg("image2.jpg");
$rgb = imagecolorat($img, $x, $y); // replace $x and $y here to be the point you want..     
imagecolorset($img, $rgb, 0, 0, 255);

 

You're also not outputting the new image to see the changes. Add this to the end of the script:

 

header('Content-type: image/jpeg');
imagejpeg($img);

 

imagejpeg

Link to comment
Share on other sites

Thanks for the reply,

 

I'am testing with both codes, but the codes don't do anything...

 

<?php
   $img = imagecreatefromjpeg("image2.jpg");
  
   $w = imagesx($img);
   $h = imagesy($img);
  
   for($y=0;$y<$h;$y++) {
      for($x=0;$x<$w;$x++) {
         $rgb = imagecolorat($img, $x, $y);        
         imagecolorset($img, $rgb, 0, 0, 0);
      }
   }
   imagejpeg($img, 'simpleimg.jpg');
?>

 

Any clue?

 

Best Regards,

Link to comment
Share on other sites

Did you change the $x and $y to the x and y of the pixel containing the color that you want to replace?

 

Yes, I have changed, but didn't see any change, so I put the code in the FOR Loops, but no changes in the image. Some clue on what could be wrong?

 

Best Regards,

 

Link to comment
Share on other sites

It should work as long as you're inputting the correct information. The script should look something like this:

 

$img = imagecreatefromjpeg("image2.jpg");
$rgb = imagecolorat($img, $x, $y); // replace $x and $y here to be the point you want..     
imagecolorset($img, $rgb, 0, 0, 255);
header('Content-type: image/jpeg');
imagejpeg($img);

 

That would take image2.jpg and take whatever color is at point ($x, $y) and replace it throughout the whole image with blue, and then display it in the browser.

Link to comment
Share on other sites

Hi,

 

Thanks for the reply.

 

I'am seeing the result with the above code, so I have tried with:

 

<?php
   $img = imagecreatefromjpeg("image2.jpg");
  
   $w = imagesx($img);
   $h = imagesy($img);
  
   for($y=0;$y<$h;$y++) {
      for($x=0;$x<$w;$x++) {
         $rgb = imagecolorat($img, $x, $y);        
         imagecolorset($img, $rgb, 0, 0, 0);
      }
   }
   imagejpeg($img, 'simpleimg.jpg');
?>

 

Unfortunately it is not working.

 

Some clue?

Link to comment
Share on other sites

$img = imagecreatefromjpeg("image2.jpg");
$rgb = imagecolorat($img, $x, $y); // replace $x and $y here to be the point you want..     
imagecolorset($img, $rgb, 0, 0, 255);
header('Content-type: image/jpeg');
imagejpeg($img, 'simpleimg.jpg');

Link to comment
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.