هذا الكود فيه مشكلة بسيطة وهي أنني عندما أضع صورة أكبر من 1.5 ميجابايت لا يتم تنفيذ تصغيرها تلقائياً حسب ما تم برمجته، فهل أجد طريقة لإلغاء هذا الخطأ؟
كود التشغيل:
$file = "images/1.jpg";
$resize = new resize_img();
$resize->quality = 60;
$resize->dirname = 'images/';
$resize->sizelimit_x = 150;
$resize->sizelimit_y = 150;
$resize->keep_proportions = true;
if($resize->thumbnail($resize->dirname . $file) === false) {
echo '<br />Thumb Erorr<br />';
} else {
$resize->save_thumbnail($resize->dirname, "s_" . $file);
}
$resize->destroy_thumbnail();
}كود الكلاس
<?php
class resize_img
{
var $dirname = 'images/';
var $quality = 99;
var $image_path = '';
var $sizelimit_x = 400;
var $sizelimit_y = 400;
var $image_resource = '';
var $keep_proportions = true;
var $resized_resource = '';
var $hasGD = false;
var $output = 'auto';
function resize_img()
{
if(function_exists('gd_info'))
{
$this->hasGD = true;
}
} #e
function resize_image($image_path)
{
if($this->hasGD === false)
{
return false;
}
list($img_width, $img_height, $img_type, $img_attr) = @getimagesize($image_path);
if(($img_width != 0) || ($img_width != 0))
{
switch ($img_type)
{
case 1:
$this->image_resource = @imagecreatefromgif($image_path);
if($this->output == 'auto')
{
$this->output = 'GIF';
}
break;
case 2:
$this->image_resource = @imagecreatefromjpeg($image_path);
if($this->output == 'auto')
{
$this->output = 'JPG';
}
break;
case 3:
$this->image_resource = @imagecreatefrompng($image_path);
if($this->output == 'auto')
{
$this->output = 'PNG';
}
}
if($this->image_resource === '')
return false;
} else
{
return false;
}
if($this->keep_proportions === true)
{
if(($img_width - $this->sizelimit_x) > ($img_height - $this->sizelimit_y))
{
$scalex = ($this->sizelimit_x / $img_width);
$scaley = $scalex;
} else
{
$scalex = ($this->sizelimit_y / $img_height);
$scaley = $scalex;
}
} else
{
$scalex = ($this->sizelimit_x / $img_width);
$scaley = ($this->sizelimit_y / $img_height);
if($scalex > 1)
{
$scalex = 1;
}
if($scaley > 1)
{
$scaley = 1;
}
}
$new_width = $img_width * $scalex;
$new_height = $img_height * $scaley;
$this->resized_resource = @imagecreatetruecolor($new_width, $new_height);
if(function_exists('imageantialias'))
{
@imageantialias($this->resized_resource, true);
}
@imagecopyresampled($this->resized_resource, $this->image_resource, 0, 0, 0, 0, $new_width, $new_height, $img_width, $img_height);
@imagedestroy($this->image_resource);
return true;
} #e
function save_resizedimage($path, $name)
{
switch (strtoupper($this->output))
{
case 'GIF':
@imagegif($this->resized_resource, $path . $name, $this->quality);
break;
case 'JPG':
@imagejpeg($this->resized_resource, $path . $name, $this->quality);
break;
case 'PNG':
@imagepng($this->resized_resource, $path . $name, $this->quality);
}
} #e
function output_resizedimage()
{
$the_time = time();
header('Last-Modified: ' . date('D, d M Y H:i:s', $the_time) . ' GMT');
header('Cache-Control: public');
switch (strtoupper($this->output))
{
case 'GIF':
header('Content-type: image/gif');
@imagegif($this->resized_resource);
break;
case 'JPG':
header('Content-type: image/jpg');
@imagejpeg($this->resized_resource);
break;
case 'PNG':
header('Content-type: image/png');
@imagepng($this->resized_resource);
}
} #e
function destroy_resized_img()
{
@imagedestroy($this->resized_resource);
@imagedestroy($this->image_resource);
} #e
} #ee
?>اتمنى وجود حل
شكراً
