PDA

View Full Version : سوال: خواهش میکنم یکی توی این کد کمکم کنه خیلی وقته نمیتونم تصاویر دریافتی رو کوچک کنم (سورس)



samadblaj
چهارشنبه 29 شهریور 1391, 12:39 عصر
سلام دوستان عزیز ببخشید من خیلی وقته میخوام عکس هام رو کوچیک کنم اما یه مشکل دارم خواهش میکنم راهنماییم کیند هر چند وقتتون رو میگیره ولی لازم دارم لطفا کمکم کنید. :ناراحت:

توی سایتم تصاویری رو با استفاده از مازول ضمیمه شده باز میکنم اما موقع نمایش عکس ها رو فقط کوچک میکنه یعنی سایز هیچ تغییری نمیکنه این کد رو توی انجمن پیدا کردم.

لطفا یکی این کد رو بزاره توی ماژولم (کد های زیادی توی انجمن پیدا کردم اما بلد نبودم استفاده کنم).


class SimpleImage {

var $image;
var $image_type;

function load($filename) {

$image_info = getimagesize($filename);
$this->image_type = $image_info[2];
if( $this->image_type == IMAGETYPE_JPEG ) {

$this->image = imagecreatefromjpeg($filename);
} elseif( $this->image_type == IMAGETYPE_GIF ) {

$this->image = imagecreatefromgif($filename);
} elseif( $this->image_type == IMAGETYPE_PNG ) {

$this->image = imagecreatefrompng($filename);
}
}
function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) {

if( $image_type == IMAGETYPE_JPEG ) {
imagejpeg($this->image,$filename,$compression);
} elseif( $image_type == IMAGETYPE_GIF ) {

imagegif($this->image,$filename);
} elseif( $image_type == IMAGETYPE_PNG ) {

imagepng($this->image,$filename);
}
if( $permissions != null) {

chmod($filename,$permissions);
}
}
function output($image_type=IMAGETYPE_JPEG) {

if( $image_type == IMAGETYPE_JPEG ) {
imagejpeg($this->image);
} elseif( $image_type == IMAGETYPE_GIF ) {

imagegif($this->image);
} elseif( $image_type == IMAGETYPE_PNG ) {

imagepng($this->image);
}
}
function getWidth() {

return imagesx($this->image);
}
function getHeight() {

return imagesy($this->image);
}
function resizeToHeight($height) {

$ratio = $height / $this->getHeight();
$width = $this->getWidth() * $ratio;
$this->resize($width,$height);
}

function resizeToWidth($width) {
$ratio = $width / $this->getWidth();
$height = $this->getheight() * $ratio;
$this->resize($width,$height);
}

function scale($scale) {
$width = $this->getWidth() * $scale/100;
$height = $this->getheight() * $scale/100;
$this->resize($width,$height);
}

function resize($width,$height) {
$new_image = imagecreatetruecolor($width, $height);
imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
$this->image = $new_image;
}

}

samadblaj
چهارشنبه 29 شهریور 1391, 18:48 عصر
یعنی کسی نمیتونه کمک من کنه ؟

kiannasim
پنج شنبه 30 شهریور 1391, 11:03 صبح
mitonid az in lib komak begirid



http://sourceforge.net/projects/phpthumb/files/phpThumb%28%29/

samadblaj
پنج شنبه 30 شهریور 1391, 13:11 عصر
mitonid az in lib komak begirid



http://sourceforge.net/projects/phpt...hpThumb%28%29/

مرسی دوست عزیز بازم معرفت شما ، میشه بفرمایید این سایته چیکار میکنه آخه من چیزی ازش نفهمیدم. :خجالت:

رضا قربانی
جمعه 31 شهریور 1391, 10:15 صبح
مرسی دوست عزیز بازم معرفت شما ، میشه بفرمایید این سایته چیکار میکنه آخه من چیزی ازش نفهمیدم. :خجالت:



function resizeToHeight($height) {
$ratio = $height / $this->getHeight();
$width = $this->getWidth() * $ratio;
$this->resize($width,$height); }
function resizeToWidth($width) {
$ratio = $width / $this->getWidth();
$height = $this->getheight() * $ratio;
$this->resize($width,$height); }



دو تابع بالارو باید ببینی چی هست و چک کنی و شاید بتونی دستی بهش عدد بدی. باید تست کنی.

===========================

در کل برای تغییر سایز باید از این کد استفاده کنید :
تغییر سایز تصاویر jpg - png - gif .... به 72*72


$time = time();
$name=strtolower( $_FILES['pic']['name']);
$ext=$name[strlen($name)-3].$name[strlen($name)-2].$name[strlen($name)-1];
$dir=base64_encode($name)."-".$time.".".$ext;
$dir=str_replace("/","-",$dir);
//////////////////////////////////////////////

if($_FILES["pic"]["type"]=="image/jpg" || $_FILES["pic"]["type"]=="image/jpeg" )
{
$uploadedfile = $_FILES['pic']['tmp_name'] ;
$src = imagecreatefromjpeg($uploadedfile) ;
}


if($_FILES["pic"]["type"]=="image/png")
{
$uploadedfile = $_FILES['pic']['tmp_name'] ;
$src = imagecreatefrompng($uploadedfile) ;
}


if($_FILES["pic"]["type"]=="image/gif")
{
$uploadedfile = $_FILES['pic']['tmp_name'] ;
$src = imagecreatefromgif($uploadedfile) ;

}

echo $uploadedfile ;
echo $src ;
list($width,$height)=getimagesize($uploadedfile);
$newwidth=72;
$newheight=72;
$tmp=imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$ne wheight,$width,$height);
$filename = "../uploading/Thumb/Reza".$dir;
imagejpeg($tmp,$filename,75);
imagedestroy($src);
imagedestroy($tmp);
//////////////////////////////////////////////


البته اینجا هم که خودتون اشاره کردید می تونید کمک بگیرید : http://barnamenevis.org/showthread.php?326722-%D8%AA%D8%BA%DB%8C%DB%8C%D8%B1-%D8%B3%D8%A7%DB%8C%D8%B2-%D8%B9%DA%A9%D8%B3-%D8%A8%D8%B9%D8%AF-%D8%A7%D8%B2-%D8%A2%D9%BE%D9%84%D9%88%D8%AF&p=1436371&highlight=%D8%AA%D8%BA%DB%8C%DB%8C%D8%B1+%D8%B3%D8 %A7%DB%8C%D8%B2+%D8%B9%DA%A9%D8%B3#post1436371
موفق باشید