خواهش میکنم یکی توی این کد کمکم کنه خیلی وقته نمیتونم تصاویر دریافتی رو کوچک کنم (سورس)
سلام دوستان عزیز ببخشید من خیلی وقته میخوام عکس هام رو کوچیک کنم اما یه مشکل دارم خواهش میکنم راهنماییم کیند هر چند وقتتون رو میگیره ولی لازم دارم لطفا کمکم کنید. :ناراحت:
توی سایتم تصاویری رو با استفاده از مازول ضمیمه شده باز میکنم اما موقع نمایش عکس ها رو فقط کوچک میکنه یعنی سایز هیچ تغییری نمیکنه این کد رو توی انجمن پیدا کردم.
لطفا یکی این کد رو بزاره توی ماژولم (کد های زیادی توی انجمن پیدا کردم اما بلد نبودم استفاده کنم).
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
مرسی دوست عزیز بازم معرفت شما ، میشه بفرمایید این سایته چیکار میکنه آخه من چیزی ازش نفهمیدم. :خجالت:
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);
//////////////////////////////////////////////
البته اینجا هم که خودتون اشاره کردید می تونید کمک بگیرید : https://barnamenevis.org/showthread.p...B3#post1436371
موفق باشید