Http://Dota.RajaGame.com/forum
 
IndeksGroupPendaftaranLoginDota.RajaGame.com

Share | 
 

 Simple Script Image Resizer & Copyright Stamp (PHP)

Go down 
PengirimMessage
DeviL_CRew
administration
administration
avatar

Jumlah posting : 17
Age : 28
Location : Jakarta
Registration date : 25.11.08

PostSubyek: Simple Script Image Resizer & Copyright Stamp (PHP)   Sat Nov 29, 2008 12:31 pm

Script Image Resizing Process (saved as image_process.class.php)

by HR

<?php

class image_process {

var $copyright = "";
var $font_size;

function create_image($source_path,$out_path,$quality=75,$width=0,$height=0,$aspect_ratio=true,$thumbnail=false) {
// get the main image
$source_image = @imagecreatefromjpeg($source_path) ;
if (!$source_image) {
return;
}
$real_width = imagesx($source_image);
$real_height = imagesy($source_image);
$landscape = false;
if ($real_width > $real_height) {
$landscape = true;
}
// scaled size
if ($width == 0) { $scaled_width = $real_width; }
else { $scaled_width = $width; }
if ($height == 0) { $scaled_height = $real_height; }
else { $scaled_width = $width; }
if ($aspect_ratio) {
$scaled_ratio = $scaled_width / $scaled_height;
$image_ratio = $real_width / $real_height;
if ($scaled_ratio < $image_ratio) {
$scaled_height = (int)($scaled_width / $image_ratio);
} else {
$scaled_width = (int)($scaled_height * $image_ratio);
}
}
// create the canvas
if ($thumbnail) {
$image_ratio = $real_width / $real_height;
if ($landscape) {
$small_height = $height;
$small_width = (int)($small_height * $image_ratio);
}
else {
$small_width = $width;
$small_height = (int)($small_width / $image_ratio);
}
if ($landscape) {
$thumb_width = ($small_width-$width) / 2;
$thumb_height = 0;
}
else {
$thumb_height = ($small_height-$height) / 2;
$thumb_width = 0;
}
$dest_image = imagecreatetruecolor($width,$height) ;
$dest_thumb = imagecreatetruecolor($small_width,$small_height) ;
imagecopyresized($dest_thumb,$source_image,0,0,0,0,$small_width,$small_height,$real_width,$real_height) ;
imagecopy($dest_image,$dest_thumb,0,0,$thumb_width,$thumb_height,$width,$height) ;
}
else {
$dest_image = imagecreatetruecolor($scaled_width,$scaled_height) ;
imagecopyresized($dest_image,$source_image,0,0,0,0,$scaled_width,$scaled_height,$real_width,$real_height) or die("Problem In Resizing");
}
$real_width = imagesx($dest_image);
$real_height = imagesy($dest_image);
// copyright
if ($this->copyright != "") {
$char_width = imagefontwidth($this->font_size);
$char_height = imagefontheight($this->font_size);
$padding = 2;
$width = $padding * 2 + strlen($this->copyright) * $char_width;
$height = + $padding * 2 + $char_height;
$background = imagecolorallocate($dest_image, 200, 200, 200);
$text = imagecolorallocate($dest_image, 0, 0, 0);
imagefilledrectangle ($dest_image, 0, 0, $width, $height, $background);
imagestring($dest_image, $this->font_size, $padding, $padding, $this->copyright, $text);
}
imagejpeg($dest_image,$out_path,$quality) ;
imagedestroy($dest_image) ;
}
}

?>
Kembali Ke Atas Go down
Lihat profil user Http://RajaGame-Community.forum-free.org
DeviL_CRew
administration
administration
avatar

Jumlah posting : 17
Age : 28
Location : Jakarta
Registration date : 25.11.08

PostSubyek: Simple Script Image Resizer & Copyright Stamp (PHP)   Sat Nov 29, 2008 12:32 pm

Script Trigger nya (save as image_upload.class.php)

by HR

<?

require_once 'image_process.class.php';

class image_upload {
function generate_image($source_file,$out_file,$path,$copyright="") {
$process = new image_process();
$process->copyright = $copyright;
$srcname = $source_file;
// create the main
$destname = $path.$out_file;
$process->font_size = 1;
$process->create_image($srcname,$destname,75,300,300,true);
// create the thumbnail
$destname = $path.'thumbnail/'.$out_file;
$process->font_size = 0;
$process->create_image($srcname,$destname,75,150,150,true);
}

}
?>


Terakhir diubah oleh RajaGame tanggal Sat Nov 29, 2008 12:34 pm, total 1 kali diubah
Kembali Ke Atas Go down
Lihat profil user Http://RajaGame-Community.forum-free.org
DeviL_CRew
administration
administration
avatar

Jumlah posting : 17
Age : 28
Location : Jakarta
Registration date : 25.11.08

PostSubyek: Simple Script Image Resizer & Copyright Stamp (PHP)   Sat Nov 29, 2008 12:34 pm

Penggunaan pada web (setelah file di upload, ditempatkan pada bagian skrip pemroses)


require_once 'image_upload.class.php';

$upload = new image_upload();

if (is_file($_FILES['photo']['tmp_name'])) {

$newname = $_FILES['photo']['name']; // nama file yg tujuan
$destpath = 'images/'; // folder tujuan
$copyright = 'CODER Team'; // copyright text
$upload->generate_image($_FILES['photo']['tmp_name'],$newname,$destpath,$copyright);
}
Kembali Ke Atas Go down
Lihat profil user Http://RajaGame-Community.forum-free.org
Sponsored content




PostSubyek: Re: Simple Script Image Resizer & Copyright Stamp (PHP)   

Kembali Ke Atas Go down
 
Simple Script Image Resizer & Copyright Stamp (PHP)
Kembali Ke Atas 
Halaman 1 dari 1
 Similar topics
-
» Red Ninja Surabaya Simple aja deh
» Red ninja cutting sticker (simple modified)
» bikin blog hemat energi!
» sharing game2 asah otak aja..
» [share] Caraku terhindar 100% dari Virus PC & Notebook ( No Deep Freeze )

Permissions in this forum:Anda tidak dapat menjawab topik
Http://Dota.RajaGame.com/forum :: Informasi & Technology :: Programing-
Navigasi: