|
Posted by Rob Adams on 01/21/05 18:33
Ok - I've finally got something that sometimes works.
http://smada.com/images/hide_image.php
I talked to a Delphi programmer, who whipped something out in about 20
minutes. My code is a translation of his.
function colorParts($col)
{
$parts['r'] = ($col >> 16) & 0xFF;
$parts['g'] = ($col >> 8) & 0xFF;
$parts['b'] = $col & 0xFF;
return $parts;
}
function NewRange($oldval)
{
return floor($oldval/255*80+87);
}
function ShiftVal($ov1, $ov2)
{
$nv = floor($ov1 + 1.8 * (newrange(127) - $ov2));
if ($nv < 0)
return 0;
else if ($nv > 255)
return 255;
else
return $nv;
}
function nrw ($oldcol)
{
$newr = NewRange(($oldcol >> 16) & 0xFF);
$newg = NewRange(($oldcol >> 8) & 0xFF);
$newb = NewRange($oldcol & 0xFF);
return ($newr << 16) + ($newg << 8) + $newb;
}
function svw($oc1, $oc2)
{
$p1 = colorParts($oc1);
$p2 = colorParts($oc2);
$nvr = ShiftVal($p1['r'],$p2['r']);
$nvg = ShiftVal($p1['g'],$p2['g']);
$nvb = ShiftVal($p1['b'],$p2['b']);
return ($nvr << 16) + ($nvg << 8) + $nvb;
}
function &openImage($file, $forcetruecolor = false)
{
$data = getimagesize($file);
$res = null;
switch($data[2])
{
case 1:
$res = imagecreatefromgif($file);
break;
case 2:
$res = imagecreatefromjpeg($file);
break;
case 3:
$res = imagecreatefrompng($file);
break;
}
if ($forcetruecolor && !imageistruecolor($res))
{
$size = getimagesize($file);
$r2 = imagecreatetruecolor($size[0], $size[1]);
imagecopy($r2, $res, 0, 0, 0, 0, $size[0], $size[1]);
imagedestroy($res);
$res =& $r2;
}
return $res;
}
include('two_image_upload.inc.php');
$main = openImage($main_file, true);
$hid = openImage($hid_file, true);
$size = getimagesize($main_file);
$size2 = getimagesize($hid_file);
$img = imagecreatetruecolor($size[0], $size[1]);
for ($y = 0; $y < $size[1]; $y++)
{
$y2 = floor(($y / $size[1]) * $size2[1]);
for ($x = 0; $x < $size[0]; $x++)
{
$x2 = floor(($x / $size[0]) * $size2[0]);
if (($x + $y) % 2 == 0) //use main image
imagesetpixel($img, $x, $y, imagecolorat($main, $x, $y));
else //use hidden image
{
$color = imagecolorat($hid, $x2, $y2);
imagesetpixel($img, $x,$y, nrw($color));
if ($y % 2 == 1)
$x3 = $x-1;
else
$x3 = $x+1;
if ($x3 >= 0 and $x3 < $size[0])
{
$color = svw(imagecolorat($img, $x3, $y), imagecolorat($img, $x,
$y));
imagesetpixel($img, $x3, $y, $color);
}
}
}
}
Navigation:
[Reply to this message]
|