الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

كلاس تصغير الصور يتوقف عندما يكون الحجم 1.5ميجابايت؟

بدأه ojopc في 7 أغسطس 2008 · 4 رد · 656 مشاهدة · في منتدى تطوير المواقع بـ PHP
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

هذا الكود فيه مشكلة بسيطة وهي أنني عندما أضع صورة أكبر من 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

?>

اتمنى وجود حل

شكراً

#2

هل يظهر لك خطأ ؟ وما هو ؟

لا إله الإ الله وحده لا شريك له الملك وله الحمد يحي ويميت وهو على كل شئ قدير

------------------------------------------------------------------------------------------------

gazabigBanner.jpg

------------------------------------------------------------------------------------------------

#3

لا يظهر أي خطأ لكني عندما استعلم عن الصورة المصغرة لا أجد انه عملها... مشكلة والله...

؟؟!!!!

#4

لا يوجد من يستطيع حل هذه المشكلة؟

غريبة

#5

ارفق كامل المثال لنرى ماهي المشكله اخي ..

لا إله الإ الله وحده لا شريك له الملك وله الحمد يحي ويميت وهو على كل شئ قدير

------------------------------------------------------------------------------------------------

gazabigBanner.jpg

------------------------------------------------------------------------------------------------

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…