MAKALAH
PROSES PEMBUATAN RGB PADA
SISTEM DIGITAL
Oleh:
Moh Erwan Agus Saputra
111080200199
FAKULTAS TEKNIK
JURUSAN TEKNIK INFORMATIKA
UNIVERSITAS MUHAMMADIYAH SIDOARJO
2014
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
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);
{
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();
$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);
//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); }
} ?>
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 ===
//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 $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);
$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);
$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>");
?>
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 ===
//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 $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);
//$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
// $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);
//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");
$dewi="hijau.jpg";
print("<P>");
print("<IMG SRC=\"$dewi\">");
print("<P>");
echo "Hasil Proses Brightness";
?>
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 ===
//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 $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);
$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)
//{
//}
//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";
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";
?>
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 "<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
}
//========================================
//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);
$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)
{
}
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";
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";
?>
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;
$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->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>";
$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("<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";
?>
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
?>
<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. Imagecolorallocatefungsi untuk menyimpan warna