Anda di halaman 1dari 41

MAKALAH

PROSES PEMBUATAN RGB PADA


SISTEM DIGITAL

Oleh:
Moh Erwan Agus Saputra
111080200199

FAKULTAS TEKNIK
JURUSAN TEKNIK INFORMATIKA
UNIVERSITAS MUHAMMADIYAH SIDOARJO
2014
1.

SKRIP GAMBAR AWAL


<div align="center"></div>
<?php
error_reporting(0);
//============ PENGOLAHAN CITRA 24 BIT =========
/*
Berikut ini adalah contoh coding mengkases citra dan menyimpannya kedalam
array berbasi structure/variabel-buatan..
*/
$dewi="asli.jpg"; //nama gambar yang diambil
$hasil = getimagesize($dewi); // ukuran awal gambar
if(! $hasil)
{
die("File $citra tidak dapat dibuka");
}
else
{
//tampilkan informasi data citra
print("<IMG SRC=\"$dewi\">");
print("<P>");
print("Lebar Citra = $hasil[0] <BR>\n");
print("Tinggi Citra = $hasil[1] <BR>\n");
print("Tipe Citra = $hasil[2] <BR>\n");
print("String Citra = $hasil[3] <BR>\n");
}
$gb=imagecreatefromJPEG($dewi); //membuat gambar yang berasal dari
sebuah URL ataupun nama sebuah file
//==== Baca Citra Ukuran Tinggi Lebar ===
list($lebar, $tinggi, $type, $attr) = getimagesize($dewi);

//yang akan menghasilkan array informasi dari file gambar yang akan kita
resize (yang diset melalui constructor)
//Tampilkan tinggi lebar citra
echo "Image width " .$lebar;
echo "<BR>";
echo "Image height " .$tinggi;
echo "<BR>";
echo "Image type " .$type;
echo "<BR>";
echo "Attribute " .$attr;
//fungsi membaca citra *.PNG
$im = imagecreatefrompng("asli.jpg");// // Load gambar dasar kami
$mhb = imagecolorat($im, 10, 15);
$r = ($mhb >> 16) & 0xFF;
$g = ($mhb >> 8) & 0xFF;
$b = $mhb & 0xFF;
var_dump($r, $g, $b);
//untuk melihat proses di PHP
//syntax membaca citra *.JPG
$im = imagecreatefromjpeg($dewi);
$mhb = imagecolorat($im, 10, 15);
$r = ($mhb >> 16) & 0xFF;
$g = ($mhb >> 8) & 0xFF;
$b = $mhb & 0xFF;
//var_dump($r, $g, $b);
//=== Variabel Buatan/Struc/Structure ====
class datamhb
{
public $R; //untuk red

public $G; //untuk green


public $B; //untuk blue
public $gray; //untuk gray
public $teks; //misalnya
}
//========================================
//contoh mengakses variabel biasa berbasis struct
$data = new datamhb();
$data->R =30;
$data->G =15;
$data->B =244;
$data->gray =40;
//CONTOH mengakses variabel Array D1 berbasis struct
$dt[] = new datamhb();
$dt[1]->R =30;
$dt[1]->G =15;
$dt[1]->B =244;
echo $dt[1]->gray =40;
//CONTOH mengakses variabel Array D2 berbasis struct
$DATA[][] = new datamhb();
$DATA[1][3]->R =30;
$DATA[1][3]->G =15;
$DATA[1][3]->B =244;
$DATA[1][3]->gray =40;
// ==== BACA mhb Citra =====
$im = imagecreatefromjpeg($dewi);
$imred = imagecreatefromjpeg($dewi);
$imgreen = imagecreatefromjpeg($dewi);

$imblue = imagecreatefromjpeg($dewi);
$x=0;
$dtmhb[][] = new datamhb();
for($x==0;$x<$lebar-1;$x++)
{
$im = imagecreatefromjpeg($dewi);
$y=0;
for($y==0;$y<$tinggi-1;$y++)
{
//echo "y=". $y . ", x=" . $x . "</BR>";
//Ambil Data Citra
$mhb = imagecolorat($im, $x, $y);
//Get mhb disimpan dalam variabel biasa (JADUL)
//$r = (int)(($mhb >> 16) & 0xFF); //mode JADUL
$red[$x][$y] = (int)(($mhb >> 16) & 0xFF);
$green[$x][$y] = (int)(($mhb >> 8) & 0xFF);
$blue[$x][$y] = (int)($mhb & 0xFF);
$gray[$x][$y]= (int)(($r+$g+$b)/3);
//Simpan data mhb to Array berbasis Structure
$dtmhb[$x][$y]->R= (int)(($mhb >> 16) & 0xFF);
$dtmhb[$x][$y]->G= (int)(($mhb >> 8) & 0xFF);
$dtmhb[$x][$y]->B= (int)($mhb & 0xFF);
$dtmhb[$x][$y]->gray= (int)(($r+$g+$b)/3);
//tampilkan data mhb
//echo "Matrik [$x,$y] R=$r, G=$g, B=$b <BR>";
//tulis pixel
$gray = imagecolorallocate($im2, $dtmhb[$x][$y]->gray, $dtmhb[$x]
[$y]->gray, $dtmhb[$x][$y]->gray);
$merah = imagecolorallocate($imred, $dtmhb[$x][$y]->R, 0, 0);

$hijau = imagecolorallocate($imgreen, 0, $dtmhb[$x][$y]->G, 0);


$biru = imagecolorallocate($imblue, 0, 0, $dtmhb[$x][$y]->B);
// set $from to $to if hex matches.
imagesetpixel($imred, $x, $y, $merah);
imagesetpixel($imgreen, $x, $y, $hijau);
imagesetpixel($imblue, $x, $y, $biru);
//imagesetpixel($imgray, $x, $y, $gray);
}
}
?>
HASIL GAMBAR

2.
Gambar RGB (BIRU)
<?php
error_reporting(0);

//============ PENGOLAHAN CITRA 24 BIT =========


/*
Berikut ini adalah contoh coding mengkases citra dan menyimpannya kedalam array berbasi
structure/variabel-buatan..
*/
$dewi="asli.jpg";
$hasil = getimagesize($dewi);
if(! $hasil)
{
die("File $citra tidak dapat dibuka");
}
else
{
//tampilkan informasi data citra
//print("<IMG SRC=\"$dewi\">");
//print("<P>");
//print("Lebar Citra = $hasil[0] <BR>\n");
//print("Tinggi Citra = $hasil[1] <BR>\n");
//print("Tipe Citra = $hasil[2] <BR>\n");
//print("String Citra = $hasil[3] <BR>\n");
}
$gb=imagecreatefromJPEG($dewi);
//==== Baca Citra Ukuran Tinggi Lebar ===
list($lebar, $tinggi, $type, $attr) = getimagesize($dewi);
//Tampilkan tinggi lebar citra
echo "Image width " .$lebar;
echo "<BR>";
echo "Image height " .$tinggi;
echo "<BR>";

echo "Image type " .$type;


echo "<BR>";
echo "Attribute " .$attr;
//fungsi membaca citra *.PNG
$im = imagecreatefrompng("asli.jpg");
$mhb = imagecolorat($im, 10, 15);
$m = ($mhb >> 16) & 0xFF;
$h = ($mhb >> 8) & 0xFF;
$b = $mhb & 0xFF;
var_dump($m, $h, $b);
//syntax membaca citra *.JPG
$im = imagecreatefromjpeg($dewi);
$mhb = imagecolorat($im, 10, 15);
$m = ($mhb >> 16) & 0xFF;
$h = ($mhb >> 8) & 0xFF;
$b = $mhb & 0xFF;
//var_dump($r, $g, $b);
//=== Variabel Buatan/Struc/Structure ====
class dataMHB
{
public $M; //untuk red
public $H; //untuk green
public $B; //untuk blue
public $gray; //untuk gray
public $teks; //misalnya
}
//=======================================
//contoh mengakses variabel biasa berbasis struct

$data = new dataMHB();


$data->M =30;
$data->H =15;
$data->B =244;
$data->gray =40;
//CONTOH mengakses variabel Array D1 berbasis struct
$dt[] = new dataMHB();
$dt[1]->M =30;
$dt[1]->H =15;
$dt[1]->B =244;
echo $dt[1]->gray =40;
//CONTOH mengakses variabel Array D2 berbasis struct
$DATA[][] = new dataMHB();
$DATA[1][3]->M =30;
$DATA[1][3]->H =15;
$DATA[1][3]->B =244;
$DATA[1][3]->gray =40;
// ==== BACA RGB Citra =====
$im = imagecreatefromjpeg($dewi);
$imred = imagecreatefromjpeg($dewi);
$imgreen = imagecreatefromjpeg($dewi);
$imblue = imagecreatefromjpeg($dewi);
$imblue1 = imagecreatefromjpeg($dewi);
$x=0;
$dtMHB[][] = new dataMHB();
for($x==0;$x<$lebar-1;$x++)
{
$im = imagecreatefromjpeg($dewi);

$y=0;
for($y==0;$y<$tinggi-1;$y++)
{
//echo "y=". $y . ", x=" . $x . "</BR>";
//Ambil Data Citra
$mhb = imagecolorat($im, $x, $y);
//Get RGB disimpan dalam variabel biasa (JADUL)
//$r = (int)(($rgb >> 16) & 0xFF); //mode JADUL
$red[$x][$y] = (int)(($mhb >> 13) & 0xFF);
$green[$x][$y] = (int)(($mhb >> 8) & 0xFF);
$blue[$x][$y] = (int)($mhb & 0xFF);
$gray[$x][$y]= (int)(($m+$h+$b)/3);
//Simpan data RGB to Array berbasis Structure
$dtMHB[$x][$y]->M= (int)(($mhb >> 13) & 0xFF);
$dtMHB[$x][$y]->H= (int)(($mhb >> 8) & 0xFF);
$dtMHB[$x][$y]->B= (int)($mhb & 0xFF);
$dtMHB[$x][$y]->gray= (int)(($m+$h+$b)/3);
//tampilkan data RGB
//echo "Matrik [$x,$y] R=$r, G=$g, B=$b <BR>";
//tulis pixel
$gray = imagecolorallocate($im2, $dtMHB[$x][$y]->gray, $dtMHB[$x][$y]->gray,
$dtMHB[$x][$y]->gray);
$merah = imagecolorallocate($imred, $dtMHB[$x][$y]->M, 0, 0);
$hijau = imagecolorallocate($imgreen, 0, $dtMHB[$x][$y]->H, 0);
$biru1 = imagecolorallocate($imblue1, 0, 0, $dtMHB[$x][$y]->B);
$biru = imagecolorallocate($imblue, 60, 80, $dtMHB[$x][$y]->B);
// set $from to $to if hex matches.
imagesetpixel($imred, $x, $y, $merah);
imagesetpixel($imgreen, $x, $y, $hijau);

imagesetpixel($imblue, $x, $y, $biru);


imagesetpixel($imblue1, $x, $y, $biru1);
//imagesetpixel($imgray, $x, $y, $gray);
}
}
echo"<br>";
echo"<br>";
imagepng($imblue1, "gambar.jpg");
imagedestroy($imblue1);
echo "Sebelum Proses Brightness";
$dewi="gambar.jpg";
print("<P>");
print("<IMG SRC=\"$dewi\">");
print("<P>");
//Simpan Citra Gray
imagepng($imblue, "biru.jpg");
imagedestroy($imblue);

$dewi="biru.jpg";
print("<P>");
print("<IMG SRC=\"$dewi\">");
print("<P>");
echo "Hasil Proses Brightness";
?>
HASIL GAMBAR

3.
SKRIP RGB HIJAU

<?php
error_reporting(0);
//============ PENGOLAHAN CITRA 24 BIT =========
/*
Berikut ini adalah contoh coding mengkases citra dan menyimpannya kedalam array berbasi
structure/variabel-buatan..
*/
$dewi="asli.jpg";
$hasil = getimagesize($dewi);
if(! $hasil)
{
die("File $citra tidak dapat dibuka");
}
else
{
//tampilkan informasi data citra
//print("<IMG SRC=\"$dewi\">");
//print("<P>");
//print("Lebar Citra = $hasil[0] <BR>\n");
//print("Tinggi Citra = $hasil[1] <BR>\n");
//print("Tipe Citra = $hasil[2] <BR>\n");
//print("String Citra = $hasil[3] <BR>\n");
}
$gb=imagecreatefromJPEG($dewi);
//==== Baca Citra Ukuran Tinggi Lebar ===
list($lebar, $tinggi, $type, $attr) = getimagesize($dewi);
//Tampilkan tinggi lebar citra
echo "Image width " .$lebar;
echo "<BR>";

echo "Image height " .$tinggi;


echo "<BR>";
echo "Image type " .$type;
echo "<BR>";
echo "Attribute " .$attr;
//fungsi membaca citra *.PNG
$im = imagecreatefrompng("asli.jpg");
$mhb = imagecolorat($im, 10, 15);
$m = ($mhb >> 16) & 0xFF;
$h = ($mhb >> 8) & 0xFF;
$b = $mhb & 0xFF;
var_dump($m, $h, $b);
//syntax membaca citra *.JPG
$im = imagecreatefromjpeg($dewi);
$mhb = imagecolorat($im, 10, 15);
$m = ($mhb >> 16) & 0xFF;
$h = ($mhb >> 8) & 0xFF;
$b = $mhb & 0xFF;
//var_dump($r, $g, $b);

//=== Variabel Buatan/Struc/Structure ====


class dataMHB
{
public $M; //untuk red
public $H; //untuk green
public $B; //untuk blue
public $gray; //untuk gray

public $teks; //misalnya


}
//=======================================
//contoh mengakses variabel biasa berbasis struct
$data = new dataMHB();
$data->M =30;
$data->H =15;
$data->B =244;
$data->gray =40;
//CONTOH mengakses variabel Array D1 berbasis struct
$dt[] = new dataMHB();
$dt[1]->M =30;
$dt[1]->H =15;
$dt[1]->B =244;
echo $dt[1]->gray =40;
//CONTOH mengakses variabel Array D2 berbasis struct
$DATA[][] = new dataMHB();
$DATA[1][3]->M =30;
$DATA[1][3]->H =15;
$DATA[1][3]->B =244;
$DATA[1][3]->gray =40;
// ==== BACA RGB Citra =====
$im = imagecreatefromjpeg($dewi);
//$imred = imagecreatefromjpeg($dewi);
$imgreen = imagecreatefromjpeg($dewi);
//$imblue = imagecreatefromjpeg($dewi);
$imgreen1 = imagecreatefromjpeg($dewi);
$x=0;

$dtMHB[][] = new dataMHB();


for($x==0;$x<$lebar-1;$x++)
{
$im = imagecreatefromjpeg($dewi);
$y=0;
for($y==0;$y<$tinggi-1;$y++)
{
//echo "y=". $y . ", x=" . $x . "</BR>";
//Ambil Data Citra
$mhb = imagecolorat($im, $x, $y);
//Get RGB disimpan dalam variabel biasa (JADUL)
//$r = (int)(($rgb >> 16) & 0xFF); //mode JADUL
$red[$x][$y] = (int)(($mhb >> 13) & 0xFF);
$green[$x][$y] = (int)(($mhb >> 8) & 0xFF);
$blue[$x][$y] = (int)($mhb & 0xFF);
$gray[$x][$y]= (int)(($m+$h+$b)/3);
//Simpan data RGB to Array berbasis Structure
$dtMHB[$x][$y]->M= (int)(($mhb >> 13) & 0xFF);
$dtMHB[$x][$y]->H= (int)(($mhb >> 8) & 0xFF);
$dtMHB[$x][$y]->B= (int)($mhb & 0xFF);
$dtMHB[$x][$y]->gray= (int)(($m+$h+$b)/3);
//tampilkan data RGB
//echo "Matrik [$x,$y] R=$r, G=$g, B=$b <BR>";
//tulis pixel
$gray = imagecolorallocate($im2, $dtMHB[$x][$y]->gray, $dtMHB[$x][$y]->gray,
$dtMHB[$x][$y]->gray);
// $merah = imagecolorallocate($imred, $dtMHB[$x][$y]->M, 0, 0);
$hijau = imagecolorallocate($imgreen, 0, $dtMHB[$x][$y]->H, 0);
$hijau1 = imagecolorallocate($imgreen, 80, $dtMHB[$x][$y]->H, 80);

//$blue1 = imagecolorallocate($imblue1, 0, 0, $dtMHB[$x][$y]->B);


//$biru = imagecolorallocate($imblue, 60, 80, $dtMHB[$x][$y]->B);
// set $from to $to if hex matches.
//imagesetpixel($imred, $x, $y, $merah);
imagesetpixel($imgreen, $x, $y, $hijau);
//imagesetpixel($imblue, $x, $y, $biru);
imagesetpixel($imgreen1, $x, $y, $hijau1);
//imagesetpixel($imgray, $x, $y, $gray);
}
}
echo"<br>";
echo"<br>";
imagepng($imgreen1, "gambar.jpg");
imagedestroy($imgreen1);
echo "Sebelum Proses Brightness";
$dewi="gambar.jpg";
print("<P>");
print("<IMG SRC=\"$dewi\">");
print("<P>");
//Simpan data RGB to Array berbasis Structure
$dtMHB[$x][$y]->M= (int)(($mhb >> 13) & 0xFF);
$dtMHB[$x][$y]->H= (int)(($mhb >> 8) & 0xFF);
$dtMHB[$x][$y]->B= (int)($mhb & 0xFF);
$dtMHB[$x][$y]->gray= (int)(($m+$h+$b)/3);
//tampilkan data RGB
//echo "Matrik [$x,$y] R=$r, G=$g, B=$b <BR>";
//tulis pixel
$gray = imagecolorallocate($im2, $dtMHB[$x][$y]->gray, $dtMHB[$x][$y]->gray,
$dtMHB[$x][$y]->gray);

$merah = imagecolorallocate($imred, $dtMHB[$x][$y]->M, 0, 0);


$hijau = imagecolorallocate($imgreen, 0, $dtMHB[$x][$y]->H, 0);
$hijau1 = imagecolorallocate($imgreen1, 0, $dtMHB[$x][$y]->H, 0);
$biru1 = imagecolorallocate($imblue1, 0, 0, $dtMHB[$x][$y]->B);
$biru = imagecolorallocate($imblue, 60, 80, $dtMHB[$x][$y]->B);
// set $from to $to if hex matches.
imagesetpixel($imred, $x, $y, $merah);
imagesetpixel($imgreen, $x, $y, $hijau);
imagesetpixel($imblue, $x, $y, $biru);
imagesetpixel($imgreen1, $x, $y, $hijau1);
//imagesetpixel($imgray, $x, $y, $gray);
}
}
echo"<br>";
echo"<br>";
imagepng($imgreen1, "gambar.jpg");
imagedestroy($imgreen1);
echo "Sebelum Proses Brightness";
$dewi="gambar.jpg";
print("<P>");
print("<IMG SRC=\"$dewi\">");
print("<P>");
//Simpan Citra Gray
imagepng($imgreen, "hijau.jpg");
imagedestroy($imgreen);
$dewi="hijau.jpg";
print("<P>");
print("<IMG SRC=\"$dewi\">");

print("<P>");
echo "Hasil Proses Brightness";
?>

HASIL GAMBAR

4.
Skrip RGB (merah)

<?php
error_reporting(0);
//============ PENGOLAHAN CITRA 24 BIT =========
/*
Berikut ini adalah contoh coding mengkases citra dan menyimpannya kedalam array berbasi
structure/variabel-buatan..
*/
$dewi="asli.jpg";
$hasil = getimagesize($dewi);
if(! $hasil)
{
die("File $citra tidak dapat dibuka");
}
else
{
//tampilkan informasi data citra
//print("<IMG SRC=\"$dewi\">");
//print("<P>");
//print("Lebar Citra = $hasil[0] <BR>\n");
//print("Tinggi Citra = $hasil[1] <BR>\n");
//print("Tipe Citra = $hasil[2] <BR>\n");
//print("String Citra = $hasil[3] <BR>\n");
}
$gb=imagecreatefromJPEG($dewi);
//==== Baca Citra Ukuran Tinggi Lebar ===
list($lebar, $tinggi, $type, $attr) = getimagesize($dewi);
//Tampilkan tinggi lebar citra
echo "Image width " .$lebar;
echo "<BR>";

echo "Image height " .$tinggi;


echo "<BR>";
echo "Image type " .$type;
echo "<BR>";
echo "Attribute " .$attr;
//fungsi membaca citra *.PNG
$im = imagecreatefrompng("asli.jpg");
$mhb = imagecolorat($im, 10, 15);
$m = ($mhb >> 16) & 0xFF;
$h = ($mhb >> 8) & 0xFF;
$b = $mhb & 0xFF;
var_dump($m, $h, $b);
//syntax membaca citra *.JPG
$im = imagecreatefromjpeg($dewi);
$mhb = imagecolorat($im, 10, 15);
$m = ($mhb >> 16) & 0xFF;
$h = ($mhb >> 8) & 0xFF;
$b = $mhb & 0xFF;
//var_dump($r, $g, $b);
//=== Variabel Buatan/Struc/Structure ====
class dataMHB
{
public $M; //untuk red
public $H; //untuk green
public $B; //untuk blue
public $gray; //untuk gray
public $teks; //misalnya
}

//========================================
//contoh mengakses variabel biasa berbasis struct
$data = new dataMHB();
$data->M =30;
$data->H =15;
$data->B =244;
$data->gray =40;
//CONTOH mengakses variabel Array D1 berbasis struct
$dt[] = new dataMHB();
$dt[1]->M =30;
$dt[1]->H=15;
$dt[1]->B =244;
echo $dt[1]->gray =40;
//CONTOH mengakses variabel Array D2 berbasis struct
$DATA[][] = new dataMHB();
$DATA[1][3]->M =30;
$DATA[1][3]->H =15;
$DATA[1][3]->B =244;
$DATA[1][3]->gray =40;
// ==== BACA RGB Citra =====
$im = imagecreatefromjpeg($dewi);
$imred = imagecreatefromjpeg($dewi);
$imred1 = imagecreatefromjpeg($dewi);
//$imgreen = imagecreatefromjpeg($dewi);
//$imblue = imagecreatefromjpeg($dewi);
$imgray = imagecreatefromjpeg($dewi);
$x=0;
$dtMHB[][] = new dataMHB();

for($x==0;$x<$lebar-1;$x++)
{
$im = imagecreatefromjpeg($dewi);
$y=0;
for($y==0;$y<$tinggi-1;$y++)
{
//echo "y=". $y . ", x=" . $x . "</BR>";
//Ambil Data Citra
$mhb = imagecolorat($im, $x, $y);
//Get RGB disimpan dalam variabel biasa (JADUL)
//$r = (int)(($rgb >> 16) & 0xFF); //mode JADUL
$red[$x][$y] = (int)(($mhb >> 13) & 0xFF);
$green[$x][$y] = (int)(($mhb >> 8) & 0xFF);
$blue[$x][$y] = (int)($mhb & 0xFF);
//$gray[$x][$y]= (int)(($m+$h+$b)/3);
//Simpan data RGB to Array berbasis Structure
$dtMHB[$x][$y]->M= (int)(($mhb >> 13) & 0xFF);
$dtMHB[$x][$y]->H= (int)(($mhb >> 8) & 0xFF);
$dtMHB[$x][$y]->B= (int)($mhb & 0xFF);
$gray[$x][$y]= (int)(($m+$h+$b)/3);
//$dtMHB[$x][$y]->gray=(int)(($dtMHB[$x][$y]->M+$dtMHB[$x][$y]>H+$dtMHB[$x][$y]->B)/3);
//$dtMHB[$x][$y]->gray= $dtMHB[$x][$y]->gray+100;
//if($dtMHB[$x][$y]->gray > 255)
//{
//$dtMHB[$x][$y]->gray=255;
//}
//if($dtMHB[$x][$y]->gray < 0)
//{

//$dtMHB[$x][$y]->gray=0;
//}
//tampilkan data RGB
//echo "Matrik [$x,$y] R=$r, G=$g, B=$b <BR>";
//tulis pixel
$gray = imagecolorallocate($imgray, $dtMHB[$x][$y]->M,$dtMHB[$x][$y]->gray,
$dtMHB[$x][$y]->gray);
$merah1 = imagecolorallocate($imred1, $dtMHB[$x][$y]->M, 0, 0);
$merah = imagecolorallocate($imred, $dtMHB[$x][$y]->M, 80, 50);
//$hijau = imagecolorallocate($imgreen, 0, $dtMHB[$x][$y]->H, 0);
//$biru = imagecolorallocate($imblue, 0, 0, $dtMHB[$x][$y]->B);
// set $from to $to if hex matches.
imagesetpixel($imred1, $x, $y, $merah1);
imagesetpixel($imred, $x, $y, $merah);
// imagesetpixel($imgreen, $x, $y, $hijau);
//imagesetpixel($imblue, $x, $y, $biru);
//imagesetpixel($im2, $x, $y, $gray);
imagesetpixel($imgray, $x, $y, $gray);
}
}
echo"<br>";
echo"<br>";
imagepng($imred1, "merah1.jpg");
imagedestroy($imred1);
echo "Sebelum Proses Brightness";
$dewi="merah1.jpg";
print("<P>");
print("<IMG SRC=\"$dewi\">");
print("<P>");

//Simpan Citra Gray


imagepng($imred, "merah.jpg");
imagedestroy($imred);
$dewi="merah.jpg";
print("<P>");
print("<IMG SRC=\"$dewi\">");
print("<P>");
echo "Hasil Proses Brightness";
//Simpan Citra Gray
// imagepng($imgray, "gray.jpg");
// imagedestroy($imgray);
//$dewi="gray.jpg";
//print("<P>");
print("<IMG SRC=\"$dewi\">");
print("<P>");
echo "Hasil Proses Brightness";
?>

HASIL GAMBAR MERAH

5.
SKRIP GRAY
<?php
error_reporting(0);
//============ PENGOLAHAN CITRA 24 BIT =========
/*
Berikut ini adalah contoh coding mengkases citra dan menyimpannya kedalam array berbasi
structure/variabel-buatan..
*/
$dewi="asli.jpg";
$hasil = getimagesize($dewi);

if(! $hasil)
{
die("File $citra tidak dapat dibuka");
}
else
{
//tampilkan informasi data citra
//print("<IMG SRC=\"$dewi\">");
//print("<P>");
//print("Lebar Citra = $hasil[0] <BR>\n");
//print("Tinggi Citra = $hasil[1] <BR>\n");
//print("Tipe Citra = $hasil[2] <BR>\n");
//print("String Citra = $hasil[3] <BR>\n");
}
$gb=imagecreatefromJPEG($dewi);
//==== Baca Citra Ukuran Tinggi Lebar ===
list($lebar, $tinggi, $type, $attr) = getimagesize($dewi);
//Tampilkan tinggi lebar citra
echo "Image width " .$lebar;
echo "<BR>";
echo "Image height " .$tinggi;
echo "<BR>";
echo "Image type " .$type;
echo "<BR>";
echo "Attribute " .$attr;
//fungsi membaca citra *.PNG
$im = imagecreatefrompng("asli.jpg");
$mhb = imagecolorat($im, 10, 15);

$m = ($mhb >> 16) & 0xFF;


$h = ($mhb >> 8) & 0xFF;
$b = $mhb & 0xFF;
var_dump($m, $h, $b);
//syntax membaca citra *.JPG
$im = imagecreatefromjpeg($dewi);
$mhb = imagecolorat($im, 10, 15);
$m = ($mhb >> 16) & 0xFF;
$h = ($mhb >> 8) & 0xFF;
$b = $mhb & 0xFF;
//var_dump($r, $g, $b);
//=== Variabel Buatan/Struc/Structure ====
class dataMHB
{
public $M; //untuk red
public $H; //untuk green
public $B; //untuk blue
public $gray; //untuk gray
public $teks; //misalnya
}
//========================================
//contoh mengakses variabel biasa berbasis struct
$data = new dataMHB();
$data->M =30;
$data->H =15;
$data->B =244;
$data->gray =40;
//CONTOH mengakses variabel Array D1 berbasis struct

$dt[] = new dataMHB();


$dt[1]->M =30;
$dt[1]->H=15;
$dt[1]->B =244;
echo $dt[1]->gray =40;
//CONTOH mengakses variabel Array D2 berbasis struct
$DATA[][] = new dataMHB();
$DATA[1][3]->M =30;
$DATA[1][3]->H =15;
$DATA[1][3]->B =244;
$DATA[1][3]->gray =40;

// ==== BACA RGB Citra =====


$im = imagecreatefromjpeg($dewi);
$imred = imagecreatefromjpeg($dewi);
$imred1 = imagecreatefromjpeg($dewi);
//$imgreen = imagecreatefromjpeg($dewi);
//$imblue = imagecreatefromjpeg($dewi);
$imgray = imagecreatefromjpeg($dewi);
$x=0;
$dtMHB[][] = new dataMHB();
for($x==0;$x<$lebar-1;$x++)
{
$im = imagecreatefromjpeg($dewi);
$y=0;
for($y==0;$y<$tinggi-1;$y++)
{
//echo "y=". $y . ", x=" . $x . "</BR>";

//Ambil Data Citra


$mhb = imagecolorat($im, $x, $y);

//Get RGB disimpan dalam variabel biasa (JADUL)


//$r = (int)(($rgb >> 16) & 0xFF); //mode JADUL
$red[$x][$y] = (int)(($mhb >> 13) & 0xFF);
$green[$x][$y] = (int)(($mhb >> 8) & 0xFF);
$blue[$x][$y] = (int)($mhb & 0xFF);
//$gray[$x][$y]= (int)(($m+$h+$b)/3);
//Simpan data RGB to Array berbasis Structure
$dtMHB[$x][$y]->M= (int)(($mhb >> 13) & 0xFF);
$dtMHB[$x][$y]->H= (int)(($mhb >> 8) & 0xFF);
$dtMHB[$x][$y]->B= (int)($mhb & 0xFF);
//$gray[$x][$y]= (int)(($m+$h+$b)/3);
$dtMHB[$x][$y]->gray=(int)(($dtMHB[$x][$y]->M+$dtMHB[$x][$y]->H+
$dtMHB[$x][$y]->B)/3);
$dtMHB[$x][$y]->gray= $dtMHB[$x][$y]->gray+100;
if($dtMHB[$x][$y]->gray > 255)
{
$dtMHB[$x][$y]->gray=255;
}
if($dtMHB[$x][$y]->gray < 0)
{
$dtMHB[$x][$y]->gray=0;
}
//tampilkan data RGB
//echo "Matrik [$x,$y] R=$r, G=$g, B=$b <BR>";
//tulis pixel

$gray = imagecolorallocate($imgray, $dtMHB[$x][$y]->M,$dtMHB[$x][$y]->gray,


$dtMHB[$x][$y]->gray);
$merah1 = imagecolorallocate($imred1, $dtMHB[$x][$y]->M, 0, 0);
$merah = imagecolorallocate($imred, $dtMHB[$x][$y]->M, 80, 50);
//$hijau = imagecolorallocate($imgreen, 0, $dtMHB[$x][$y]->H, 0);
//$biru = imagecolorallocate($imblue, 0, 0, $dtMHB[$x][$y]->B);
// set $from to $to if hex matches.
imagesetpixel($imred1, $x, $y, $merah1);
imagesetpixel($imred, $x, $y, $merah);
// imagesetpixel($imgreen, $x, $y, $hijau);
//imagesetpixel($imblue, $x, $y, $biru);
imagesetpixel($im2, $x, $y, $gray);
imagesetpixel($imgray, $x, $y, $gray);
}
}
echo"<br>";
echo"<br>";
imagepng($imgray, "gray.jpg");
imagedestroy($imgray);
echo "Sebelum Proses Brightness";
$dewi="gray.jpg";
print("<P>");
print("<IMG SRC=\"$dewi\">");
print("<P>");
//Simpan Citra Gray
imagepng($imred, "merah.jpg");
imagedestroy($imred);
$dewi="merah.jpg";
print("<P>");

print("<IMG SRC=\"$dewi\">");
print("<P>");
echo "Hasil Proses Brightness";
//Simpan Citra Gray
// imagepng($imgray, "gray.jpg");
// imagedestroy($imgray);
//$dewi="gray.jpg";
//print("<P>");
print("<IMG SRC=\"$dewi\">");
print("<P>");
echo "Hasil Proses Brightness";
?>
HASIL GAMBAR GRAY

6.
SKRIP CONTRAS
<?php
error_reporting(0);
//============ PENGOLAHAN CITRA 24 BIT =========
/*
Berikut ini adalah contoh coding mengkases citra dan menyimpannya kedalam array berbasi
structure/variabel-buatan..
*/
$dewi="asli.jpg";
$hasil = getimagesize($dewi);
if(! $hasil)
{
die("File $citra tidak dapat dibuka");
}
else
{
//tampilkan informasi data citra
//print("<IMG SRC=\"$dewi\">");
//print("<P>");
//print("Lebar Citra = $hasil[0] <BR>\n");
//print("Tinggi Citra = $hasil[1] <BR>\n");
//print("Tipe Citra = $hasil[2] <BR>\n");
//print("String Citra = $hasil[3] <BR>\n");
}

$gb=imagecreatefromJPEG($dewi);
//==== Baca Citra Ukuran Tinggi Lebar ===
list($lebar, $tinggi, $type, $attr) = getimagesize($dewi);
//Tampilkan tinggi lebar citra
echo "Image width " .$lebar;
echo "<BR>";
echo "Image height " .$tinggi;
echo "<BR>";
echo "Image type " .$type;
echo "<BR>";
echo "Attribute " .$attr;
//fungsi membaca citra *.PNG
$im = imagecreatefrompng("asli.jpg");
$mhb = imagecolorat($im, 10, 15);
$m = ($mhb >> 16) & 0xFF;
$h = ($mhb >> 8) & 0xFF;
$b = $mhb & 0xFF;
var_dump($m, $h, $b);
//syntax membaca citra *.JPG
$im = imagecreatefromjpeg($dewi);
$mhb = imagecolorat($im, 10, 15);
$m = ($mhb >> 16) & 0xFF;
$h = ($mhb >> 8) & 0xFF;
$b = $mhb & 0xFF;
//var_dump($r, $g, $b);
//=== Variabel Buatan/Struc/Structure ====
class dataMHB
{

public $M; //untuk red


public $H; //untuk green
public $B; //untuk blue
public $gray; //untuk gray
public $teks; //misalnya
}
//========================================
//contoh mengakses variabel biasa berbasis struct
$data = new dataMHB();
$data->M =30;
$data->H =15;
$data->B =244;
$data->gray =40;
//CONTOH mengakses variabel Array D1 berbasis struct
$dt[] = new dataMHB();
$dt[1]->M =30;
$dt[1]->H=15;
$dt[1]->B =244;
echo $dt[1]->gray =40;
//CONTOH mengakses variabel Array D2 berbasis struct
$DATA[][] = new dataMHB();
$DATA[1][3]->M =30;
$DATA[1][3]->H =15;
$DATA[1][3]->B =244;
$DATA[1][3]->gray =40;
// ==== BACA RGB Citra =====
$im = imagecreatefromjpeg($dewi);
$imred = imagecreatefromjpeg($dewi);

$imred1 = imagecreatefromjpeg($dewi);
//$imgreen = imagecreatefromjpeg($dewi);
//$imblue = imagecreatefromjpeg($dewi);
$imgray = imagecreatefromjpeg($dewi);
$x=0;
$dtMHB[][] = new dataMHB();
for($x==0;$x<$lebar-1;$x++)
{
$im = imagecreatefromjpeg($dewi);
$y=0;
for($y==0;$y<$tinggi-1;$y++)
{
//echo "y=". $y . ", x=" . $x . "</BR>";
//Ambil Data Citra
$mhb = imagecolorat($im, $x, $y);
//Get RGB disimpan dalam variabel biasa (JADUL)
//$r = (int)(($rgb >> 16) & 0xFF); //mode JADUL
$red[$x][$y] = (int)(($mhb >> 13) & 0xFF);
$green[$x][$y] = (int)(($mhb >> 8) & 0xFF);
$blue[$x][$y] = (int)($mhb & 0xFF);
//$gray[$x][$y]= (int)(($m+$h+$b)/3);
//Simpan data RGB to Array berbasis Structure
$dtMHB[$x][$y]->M= (int)(($mhb >> 13) & 0xFF);
$dtMHB[$x][$y]->H= (int)(($mhb >> 8) & 0xFF);
$dtMHB[$x][$y]->B= (int)($mhb & 0xFF);
$gray[$x][$y]= (int)((2*40-50)+50);
//$dtMHB[$x][$y]->gray=(int)(($dtMHB[$x][$y]->M+$dtMHB[$x][$y]>H+$dtMHB[$x][$y]->B)/3);
//$dtMHB[$x][$y]->gray= $dtMHB[$x][$y]->gray+100;

if($dtMHB[$x][$y]->gray > 255)


{
$dtMHB[$x][$y]->gray=255;
}
if($dtMHB[$x][$y]->gray < 0)
{
$dtMHB[$x][$y]->gray=0;
}
//tampilkan data RGB
//echo "Matrik [$x,$y] R=$r, G=$g, B=$b <BR>";
//tulis pixel
$gray = imagecolorallocate($imgray, $dtMHB[$x][$y]->M,$dtMHB[$x][$y]->gray,
$dtMHB[$x][$y]->gray);
$merah1 = imagecolorallocate($imred1, $dtMHB[$x][$y]->M, 0, 0);
$merah = imagecolorallocate($imred, $dtMHB[$x][$y]->M, 80, 50);
//$hijau = imagecolorallocate($imgreen, 0, $dtMHB[$x][$y]->H, 0);
//$biru = imagecolorallocate($imblue, 0, 0, $dtMHB[$x][$y]->B);
// set $from to $to if hex matches.
imagesetpixel($imred1, $x, $y, $merah1);
imagesetpixel($imred, $x, $y, $merah);
// imagesetpixel($imgreen, $x, $y, $hijau);
//imagesetpixel($imblue, $x, $y, $biru);
imagesetpixel($im2, $x, $y, $gray);
imagesetpixel($imgray, $x, $y, $gray);
}
}
echo"<br>";
echo"<br>";
imagepng($imgray, "gray.jpg");

imagedestroy($imgray);
echo "Sebelum Proses Brightness";
$dewi="gray.jpg";
print("<P>");
print("<IMG SRC=\"$dewi\">");
print("<P>");
//Simpan Citra Gray
imagepng($imred, "merah.jpg");
imagedestroy($imred);
$dewi="merah.jpg";
print("<P>");
print("<IMG SRC=\"$dewi\">");
print("<P>");
echo "Hasil Proses Brightness";
//Simpan Citra Gray
// imagepng($imgray, "gray.jpg");
// imagedestroy($imgray);
//$dewi="gray.jpg";
//print("<P>");
print("<IMG SRC=\"$dewi\">");
print("<P>");
echo "Hasil Proses Brightness";
?>

HASIL CONTRAS

7.
SKRIP INDEX
<html>
<head>
<title>Dewi Yuliana Setyowati</title>
</head>

<body background=bunga.jpg>
<marquee><font size=4 face=tahoma color=green>SELAMAT DATANG</font>
<hr size=1 width=150 align=left></marquee>
<div align="center"><font size=7 face=verdana color=#FF00CC><b>PENCITRAAN
DIGITAL</b></font>
</div>
<hr size=5 align=center noshade>
<hr>
<p align="center">Judul Tugas : </p>
<p align="center">Citra_brightness_structure</p>
<p align="left">Silahkan klik menu dibawah ini untuk membandingkan hasil dari proses
Brightness </p>
<p align="left">|<a href=index.php>ASLI </a>|<a href=kedua.php>MERAH </a>|<a
href=ketiga.php>HIJAU </a>|<a href=keempat.php>BIRU</a>|
<div align="left"><font size=4 face=tahoma color=green >Ini gambar asli</font></div>
<hr><p align="center">
<body>
<?php
include("citraasli.php");
?>
<hr size=5 align=center noshade>
<p align="center">Copyright@Dewi Yuliana .S(111080200200)
</p>
</body>
</body>
</html>
HASIL GAMBAR INDEX

PENGERTIAN SKRIP2 PHP


1. Fungsi GetImageSize() disini menghasilkan array pertama yaitu lebar dari file gambar yang
akan diupload dan array kedua adalah tinggi dari gambar yang akan diupload.
2. Imagecreatefromjpeg membuat gambar yang berasal dari sebuah URL ataupun nama sebuah
file
3. Getimagesize yang akan menghasilkan array informasi dari file gambar yang akan kita resize
(yang diset melalui constructor)
4. Imagecreatefromjpeg load gambar dari sumber yang disediakan
5. Imagecolorallocate fungsi untuk menyimpan warna
6. Imagecolorat()fungsi untuk membaca warna di titik tertentu pada gambar