473,320 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

pixel values of image changes after using imagesetpixel()

I am simply taking the pixels values from jpeg image using the function imagecolorat() and then creating a jpg image back again by giving those pixel values to imagesetpixel(). the name of new image is "test.jpg". When i again extract the pixel values from this test.jpg i found that the extracted pixel values are different from those i gave to imagesetpixel().

This is the code which is taking an image (jpg), saving pixel values in 2d array "pix_arr[][]" and then creating new image (test.jpg):
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if (isset($_POST['go']))
  3. {
  4.     if ($_FILES["file"]["error"] > 0)
  5.     {
  6.         echo "Error: " . $_FILES["file"]["error"] . "<br>";
  7.  
  8.     }
  9.     else
  10.     {
  11.         $image_to_process = $_FILES["file"]["tmp_name"];
  12.         $im = imagecreatefromjpeg($image_to_process);
  13.         ////////////++++++++++++++++++++++++++++++++++++++++++++++++////////////////
  14.         ////-------IMAGE PIXEL MANIPULATION TILL CREATING ARRAY OF PIXLES-----------
  15.         {
  16.             $width =  imagesx($im);
  17.             $height = imagesy($im);
  18.             for($i=0;$i<$width;$i++)
  19.             {
  20.                 for($j=0;$j<$height;$j++)
  21.                 {
  22.                     $color_index = imagecolorat($im, $i, $j);
  23.                     $pix_arr[$i][$j] = $color_index;
  24.  
  25.                 }
  26.             }
  27.             for($i=0;$i<$width;$i++){
  28.             for($j=0;$j<$height;$j++)
  29.             {
  30.                 echo $pix_arr[$i][$j];
  31.                 ?>
  32.                 <br/>
  33.                 <?php
  34.             }
  35.             }
  36.             $img = imagecreatetruecolor($width,$height);
  37.             for ($i = 0; $i < $width; $i++)
  38.             {
  39.                 for ($j = 0; $j < $height; $j++)
  40.                 {
  41.                     imagesetpixel($img, $i, $j, $pix_arr[$i][$j]);
  42.                 }
  43.             }
  44.             imagejpeg($img, 'C:\wamp\www\testing\test.jpg');
  45.         }//anvi
  46.     }//else
  47. }
  48. ?>
  49.  
Here is the code through which i am getting the pixel values of created test.jpg. but the pixel values are different from those i set in above code.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if (isset($_POST['go']))
  3. {
  4.     if ($_FILES["file"]["error"] > 0)
  5.     {
  6.         echo "Error: " . $_FILES["file"]["error"] . "<br>";
  7.  
  8.     }
  9.     else
  10.     {
  11.         $image_to_process = $_FILES["file"]["tmp_name"];
  12.         $im = imagecreatefromjpeg($image_to_process);
  13.         ////////////++++++++++++++++++++++++++++++++++++++++++++++++////////////////
  14.         ////-------IMAGE PIXEL MANIPULATION TILL CREATING ARRAY OF PIXLES-----------
  15.         {
  16.             $width =  imagesx($im);
  17.             $height = imagesy($im);
  18.             $total_pix = $width*$height;
  19.             for($i=0;$i<$width;$i++)
  20.             {
  21.                 for($j=0;$j<$height;$j++)
  22.                 {
  23.                     $color_index = imagecolorat($im, $i, $j);
  24.                     $pix_arr[$i][$j] = $color_index;
  25.  
  26.                 }
  27.             }
  28.             for($i=0;$i<$width;$i++){
  29.             for($j=0;$j<$height;$j++)
  30.             {
  31.                 echo $pix_arr[$i][$j];
  32.                 ?>
  33.                 <br/>
  34.                 <?php
  35.             }
  36.             }
  37.         }//anvi
  38.     }//else
  39. }
  40. ?>
  41.  
Why the values are different. they must be same.

I think there is the problem in imagecreatetruecolor() or imagesetpixel().

Attached is the sample image on which i am testing.

I will be very thankful to you for your help.
Attached Images
File Type: jpg img04.jpg (333 Bytes, 91 views)
Dec 7 '13 #1
0 1063

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: khaleel.alyasini | last post by:
Hi, currently I'm working on DCT algorithm on C++. I was wondering if anyone out there could point me out how to seperate the pixel values into DCT blocks. Here, i have enclosed my source...
6
by: Lorenzo Thurman | last post by:
Does anyone know how to validate a particular image type using PHP? If I have a file and I want to ensure that it is a jpeg, how would go about it? A sort of is_jpeg or is_gif is what I'm seeking....
2
by: ajay_itbhu | last post by:
Hi everyone, I want to read the pixel values of 2 similar images in bitmap format like 2 continuous frame of a video for calculating the median. But i dont know how to read the pixel values of...
1
by: Sirisha | last post by:
Hello, I want code for insert values into database using storedprocedure and how to write stored procedures. I want code in codebehined file, imean .aspx code Regards,
0
by: Sirisha | last post by:
Hi, I am inserting values into databse using sqlserver stored procedures. i wrote stored preocedure,but in codebehind file(.vb file) i dont know how to pass the parameters, i got error message...
0
by: harwindersran | last post by:
hey guys i need implementation for tiff image zooming using DCT . its my project work.. is there anyone can help me.. it wud be very helpful to me.. nd very very thanks..
2
by: shg | last post by:
Hi, Can anyone guide me on How can I make/create a jpg file if I have image pixel values?
10
SaiRockinGuy
by: SaiRockinGuy | last post by:
Hi, How to retain values in jsp using struts2 tags. I am using <s:select></s:select> which has inbuilt properties in it. But the values are not retained when the page gets refreshed.Can...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.