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
- <?php
- if (isset($_POST['go']))
- {
- if ($_FILES["file"]["error"] > 0)
- {
- echo "Error: " . $_FILES["file"]["error"] . "<br>";
- }
- else
- {
- $image_to_process = $_FILES["file"]["tmp_name"];
- $im = imagecreatefromjpeg($image_to_process);
- ////////////++++++++++++++++++++++++++++++++++++++++++++++++////////////////
- ////-------IMAGE PIXEL MANIPULATION TILL CREATING ARRAY OF PIXLES-----------
- {
- $width = imagesx($im);
- $height = imagesy($im);
- for($i=0;$i<$width;$i++)
- {
- for($j=0;$j<$height;$j++)
- {
- $color_index = imagecolorat($im, $i, $j);
- $pix_arr[$i][$j] = $color_index;
- }
- }
- for($i=0;$i<$width;$i++){
- for($j=0;$j<$height;$j++)
- {
- echo $pix_arr[$i][$j];
- ?>
- <br/>
- <?php
- }
- }
- $img = imagecreatetruecolor($width,$height);
- for ($i = 0; $i < $width; $i++)
- {
- for ($j = 0; $j < $height; $j++)
- {
- imagesetpixel($img, $i, $j, $pix_arr[$i][$j]);
- }
- }
- imagejpeg($img, 'C:\wamp\www\testing\test.jpg');
- }//anvi
- }//else
- }
- ?>
Expand|Select|Wrap|Line Numbers
- <?php
- if (isset($_POST['go']))
- {
- if ($_FILES["file"]["error"] > 0)
- {
- echo "Error: " . $_FILES["file"]["error"] . "<br>";
- }
- else
- {
- $image_to_process = $_FILES["file"]["tmp_name"];
- $im = imagecreatefromjpeg($image_to_process);
- ////////////++++++++++++++++++++++++++++++++++++++++++++++++////////////////
- ////-------IMAGE PIXEL MANIPULATION TILL CREATING ARRAY OF PIXLES-----------
- {
- $width = imagesx($im);
- $height = imagesy($im);
- $total_pix = $width*$height;
- for($i=0;$i<$width;$i++)
- {
- for($j=0;$j<$height;$j++)
- {
- $color_index = imagecolorat($im, $i, $j);
- $pix_arr[$i][$j] = $color_index;
- }
- }
- for($i=0;$i<$width;$i++){
- for($j=0;$j<$height;$j++)
- {
- echo $pix_arr[$i][$j];
- ?>
- <br/>
- <?php
- }
- }
- }//anvi
- }//else
- }
- ?>
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.