[need help] - PHP Image manipulation...

This forum is now closed as part of retiring phpBB2.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

This forum is now closed due to phpBB2.0 being retired.
Post Reply
Peter VDD
Registered User
Posts: 140
Joined: Sun Oct 12, 2003 12:18 pm
Contact:

[need help] - PHP Image manipulation...

Post by Peter VDD »

I was writing a mod to make images by merging 2 images with some stuff around it, and all seem to work but there's one big problem (and I really can't get around): the colors resulted in the final file are wrong :(

I tried everything: inserting via .jpg, via .png, I initially split them up in their RGB values and thought the problem was when composing the full RGB back together, but even this simple script below returns an incorrect image.

Code: Select all

<?php
$im = imagecreatefrompng("input.png");
$im2 = imagecreatefrompng("input2.png");
$width = imagesx($im); 
$height = imagesy($im); 
$width2 = imagesx($im2); 
$height2 = imagesy($im2);

if (($height != $height2) || ($width != $width2)) 
{
   die ('inequal size'); 
}

$rgb = array();
for ($x=0; $x<$width; $x++) 
{ 
  for ($y=0; $y<$height; $y++) 
  { 
    $rgb[$x][$y] = imagecolorat($im,$x,$y);
  }
}
imagedestroy($im);

$rbg2 = array();
for ($x=0; $x<$width; $x++) 
{ 
  for ($y=0; $y<$height; $y++) 
  { 
    $rgb2[$x][$y] = imagecolorat($im2,$x,$y); 
  }
}
imagedestroy($im2);

$rgb3 = array();
for ($x=0; $x<$width; $x++) 
{ 
  for ($y=0; $y<$height; $y++) 
  {
    $rgb3[$x][$y] = ceil(($rgb2[$x][$y] + $rgb[$x][$y])/2);
  }
}
$im3 = @imagecreatetruecolor($width, $height);

for ($x=0; $x<$width; $x++) 
{ 
  for ($y=0; $y<$height; $y++) 
  { 
    imagesetpixel($im3,$x,$y,$rgb3[$x][$y]); 
  }
}
imagepng($im3, output.png); 
imagedestroy($im3);
echo("done.");
?>
Last edited by Peter VDD on Sun Aug 15, 2004 12:33 pm, edited 1 time in total.
Peter VDD
Registered User
Posts: 140
Joined: Sun Oct 12, 2003 12:18 pm
Contact:

Re: [need help] - PHP Image manipulation...

Post by Peter VDD »

woops pressed quote instead of edit :oops:
Peter VDD
Registered User
Posts: 140
Joined: Sun Oct 12, 2003 12:18 pm
Contact:

Post by Peter VDD »

2 days and no answer :(

gonna have to bump this one I guess...
DarkPepe
Registered User
Posts: 183
Joined: Thu Jan 16, 2003 11:24 pm
Location: Santiago, Chile
Contact:

Post by DarkPepe »

Mhmhm Helping BUMP
Post Reply

Return to “[2.0.x] MOD Writers Discussion”