Posted by : Unknown
Jumat, 04 Januari 2013
Pada kesempantan kali ini saya mau berbagi ilmu hari ini, yaout
tentang cara mengupload gambar tanpa pindah halaman dan pada gambar
tersebut terdapat watermark dari kita.
ayo kita mulai langkah-langkah berikut.
Buat file form.php
1
2
3
4
5
6
7
8
9
| <form action="upload.php" enctype="multipart/form-data" method="post"> Picture : <input name="picture" type="file"> <input name="upload" value="Upload" type="submit"></form><div id="uploaded-picture"><!-- div tempat photo yang telah diupload ditampilkan --></div><script src="jquery.js" type="text/javascript"><!--mce:0--></script> |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| function startUpload(){ $("#uploaded-picture").html("<img src="\" alt="">");}function displayPicture(pictureUrl){ var img = new Image(); $(img).load(function(){ $(this).hide(); $("#uploaded-picture").html($(this)); $(this).fadeIn(); }).attr('src', pictureUrl) .error(function(){ alert("gagal menampilkan gambar"); });} |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| <!--?php//file upload.phpinclude"image-mark.php"; $fileName = $_FILES['picture']['name']; $fileSize = $_FILES['picture']['size']; $fileError = $_FILES['picture']['error']; $success = false; if($fileSize --> 0 || $fileError == 0){ $path = "photo/"; $new=$path.'small_'.time().".jpg"; watermark_image($new); $success = true; }?><script type="text/javascript"><!--mce:1--></script> |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
| <!--?php function watermark_image($upload){ $image_show = "logo.png"; // watermark image $image_path = $image_show; $path = "photo/"; // folder upload gambar setelah proses watermark $upload_status = move_uploaded_file($_FILES['picture']['tmp_name'], $path.$_FILES['picture']['name']); $oldimage_name=$path.$_FILES['picture']['name']; $new_image_name = $upload; list($owidth,$oheight) = getimagesize($oldimage_name); $width = 500; $height = ($width/$owidth)*$oheight; // tentukan ukuran gambar akhir, contoh: 300 x 300 $im = imagecreatetruecolor($width, $height); $img_src = imagecreatefromjpeg($oldimage_name); imagecopyresampled($im, $img_src, 0, 0, 0, 0, $width, $height, $owidth, $oheight); $watermark = imagecreatefrompng($image_path); list($w_width, $w_height) = getimagesize($image_path); $pos_x = $width - $w_width; $pos_y = $height - $w_height; imagecopy($im, $watermark, $pos_x, $pos_y, 0, 0, $w_width, $w_height); imagejpeg($im, $new_image_name, 100); imagedestroy($im); unlink($oldimage_name); return $new_image_name;} ?--> |
Related Posts :
- Back to Home »
- Programmer »
- Upload Gambar Dengan Teknik jQuery + PHP Watermarking