These code snippets have been used in GrafxShop for Image Editing through different filters. Please read the notice carefully 1) before using any of the contents.
function Invert($image_path) { @header("Content-Type: image/jpeg"); $m_width = 0; $m_height = 0; $i = 0; $j = 0; $src = imagecreatefromjpeg($image_path); $m_width = imagesx($src); $m_height = imagesy($src); $im2 = imagecreatetruecolor($m_width, $m_height); for ($i = 0; $i < $m_height; $i++) { for ($j = 0; $j < $m_width; $j++) { $rgb = imagecolorat($src, $j, $i); $r = ($rgb >> 16) & 0xFF; $g = ($rgb >> 8) & 0xFF; $b = $rgb & 0xFF; $r = 255 - $r; $g = 255 - $g; $b = 255 - $b; $newcolor = imagecolorallocate($im2, $r, $g, $b); imagesetpixel($im2, $j, $i, $newcolor); } } imagejpeg($im2); imagedestroy($im2); exit; }
procedure Invert(src: tbitmap); var w, h, x, y: integer; p: pbytearray; begin w := src.Width; h := src.Height; src.PixelFormat := pf24bit; for y := 0 to h - 1 do begin p := src.scanline[y]; for x := 0 to w - 1 do begin p[x * 3] := not p[x * 3]; p[x * 3 + 1] := not p[x * 3 + 1]; p[x * 3 + 2] := not p[x * 3 + 2]; end; end; end;