Patch imagecreatefromjpeg for GD related Bug #54428
Patch version 2011-03-31 02:37 UTC
Return to Bug #54428 |
Download this patch
Patch Revisions:
Developer: hoangvu4000@gmail.com
//phien ban dùng cho tgtt.zone.vn
// upload file FTP lên server khác và dẫn link về,
// che link lại bằng URL REdirect từ TGTT.
// xuat anh co dang http://thegioitruyentranh.vn/truyentranh/images.php?500=707=uploads/0_92/MENU.jpg
$up_file = $_GET['up_file'];
$src = $_GET['src'];
// $new_width = 700;
// $new_height = 0;
$host = "your_host";
$ftpName = "your_host_user";
$ftpPass = "your_host_User_pass";
$port = 21;
$root = "/domains/anything..../public_html/";
if($src == "manga24h"){
$root_dir = "manga24h/";
}else
{
$root_dir = "truyentranh/";
}
// echo $root_dir;
// Die;
$snipURL = array("http://truyentranhtuan.com/IMAGES/MANGA/","http://media1.manga24h.com/manga","http://media2.manga24h.com/manga","http://media3.manga24h.com/manga","http://data.vechai.info/mangas/","http://");
$redirectHost ="z.thegioitruyentranh.vn";
$IMG_FILTER_CONTRAST = -15; // nang cao do tuong phan cua tranh
//print_r($snipURL);
$i = rand(1,3);
//$stamp = "watermark/logo_TheGioiTruyenTranh2010_$i.png";
$stamp = "watermark/logo_TheGioiTruyenTranh.png";
$new_image=imagecreatefromjpeg($up_file) or die ();
//(header("location:$up_file"));
$imagesize = array();
$imagesize = getimagesize($up_file) or die (header("location:$up_file"));
$width = $imagesize[0];
$height = $imagesize[1];
// watermark
$marge_right = 10;// khoản cách từ bên phải
$marge_bottom = 5;// khoản cách từ bên dưới.
@$stampxy=imagecreatefrompng($stamp);
$sx = imagesx($stampxy); //rộng của watermark
$sy = imagesy($stampxy);// cao của watermark
//imagecopy($new_image, $stampxy, $width/2 - $sx/2, $height - $sy - $marge_bottom, 0, 0, $sx, $sy); //center - buttom
// ngau nhien, lúc có watermark, lúc không!
if ($i==1){
imagecopy($new_image, $stampxy, $width - $sx - $marge_right, $height - $sy - $marge_bottom, 0, 0, $sx, $sy); //right - buttom
}else if($i==2){
imagecopy($new_image, $stampxy, $marge_right, $marge_bottom, 0, 0, $sx, $sy); //left - top
}
//Grab new image
ob_start();
imagefilter($new_image, IMG_FILTER_CONTRAST, $IMG_FILTER_CONTRAST); // tăng độ tương phản lên 15%, để giảm các nét nhòe.
ImageJPEG($new_image);
$image_buffer = ob_get_contents();
ob_end_clean();
ImageDestroy($new_image);
//Create temporary file and write to it
$fp = tmpfile();
fwrite($fp, $image_buffer);
rewind($fp);
//Upload new image
//$imageFullPath = str_replace('http://','',$up_file); // like: upanh.com/images/bbcode/music.gif
$imageFullPath = str_replace($snipURL,'',$up_file); // like: upanh.com/images/bbcode/music.gif
$imageFileName = fGetFileName($imageFullPath); // like: music.gif
$imageStorePath = str_replace($imageFileName,'',$imageFullPath); // like: upanh.com/images/
$imageStorePathFinal = $root.$root_dir.$imageStorePath; // like: /domains/img.thegioitruyentranh.vn/public_html/r200/upanh.com/images/
$conn_id = ftp_connect($host, $port);
ftp_login($conn_id,$ftpName,$ftpPass) or die('login fail');;
ftp_mkdir_recursive($conn_id, 0777, $imageStorePathFinal) or die('An error while creating a directory occured.');
ftp_fput($conn_id,$imageStorePathFinal.$imageFileName, $fp, FTP_BINARY);
fclose($fp);
header("location:http://$redirectHost/$root_dir".$imageFullPath);
?>
<?PHP
////////////////////////////////////////////////////////////////////////
/// functions
function fGetFileName($sFilePath)
{
$tam=explode("/",$sFilePath);
return $tam[count($tam)-1];
}
/// functions
function fGetFileExt($sFilePath)
{
$tam=explode(".",$sFilePath);
return $tam[count($tam)-1];
}
function ftp_mkdir_recursive($ftpconn_id, $mode, $path)
{
$dir=split("/", $path);
$path="";
$ret = true;
for ($i=0;$i<count($dir);$i++)
{
$path.="/".$dir[$i];
if(!@ftp_chdir($ftpconn_id,$path))
{
@ftp_chdir($ftpconn_id,"/");
if(!@ftp_mkdir($ftpconn_id,$path))
{
$ret=false;
break;
} else {
@ftp_chmod($ftpconn_id, $mode, $path);
}
}
}
return $ret;
}
|