تغییر سایز عکس

o_real_love

Well-Known Member
سلام دوباره به بچه ها
من یک سایت دارم میزنم که یک گالری عکس میخواد
میخوام وقتی ادمین از کنترل پنل عکسی رو آپلود کرد عکس دو تا تغییر سایز داده بشه
مثلا یکی 500 در 400 بشه
و یکی هم 150 در100 بشه
بعد بتونم عکس کوچیکو تو گالری نشون بدم و وقتی روی عکس کوچیکه کلیک کرد عکس بزرگش نشون داده بشه
افتاد الان که من چی میخوام
کسی هست بتونه کمک کنه
حالا اسکریپت داره یا چیزه دیکه
کمک کنید
پولشو با هم نصف میکنیم:green::cool::lol:
 

iman_ebru

Active Member
1. این کد رو در ادیتورت کپی و بعد ذخیره کن.
2. چند تا تصویر رو در کنار همون فایل کپی کن.
3. در مرورگرت به آدرس www.your-web-server.com/File.php?picture=FileName برو!
4. در Tab دیگر مرورگر به www.your-web-server.com/File.php?picture=FileName&thumbnail=1 برو!

* تصویر اول تصویر بزرگ و تصویر دوم همان کوچک شده تصویر هست.!

* سطر 11 و 16 مربوط به تصویر کوچک شده و سطر 24 و 29 مربوط به تصویر بزرگ هست!

* این کد رو برای نمایش عکس مربوط به خبر یک سایت خبرگزاری نوشتم... که در صفحه اول در سایز 150 و در محتوا با اندازه 500 پیکسل نشون میده.

از imagecreatefromjpeg برای JPEG or JPG تولید و از imagecreatefrompng برای تولید PNG و از imagecreatefromgif برای تولید GIF استفاده کردم.


PHP:
<?php
 Header("Content-type: image/jpeg");
 
 $thumbnail_picture = $_GET['picture'];
 list($width, $height) = getimagesize($thumbnail_picture);

 if(isset($_GET['thumbnail']) and ($_GET['thumbnail'] == '1'))
 {
	 if($width>$height)
	 {
		 $thumbnail_width = '150';
		 $thumbnail_height = (($thumbnail_width*$height)/$width);
	 }
	 else
	 {
		 $thumbnail_height = '150';
		 $thumbnail_width = (($thumbnail_height*$width)/$height);
	 }
 }
 else
 {
	 if($width>$height)
	 {
		 $thumbnail_width = '500';
		 $thumbnail_height = (($thumbnail_width*$height)/$width);
	 }
	 else
	 {
		 $thumbnail_height = '500';
		 $thumbnail_width = (($thumbnail_height*$width)/$height);
	 }
 }

 
 $system = explode('.',strtolower($thumbnail_picture));
 
 if (preg_match('/jpg|jpeg/',$system[1])){
 $orig_image = imagecreatefromjpeg($thumbnail_picture);
 }
 
 if (preg_match('/png/',$system[1])){
 $orig_image = imagecreatefrompng($thumbnail_picture);
 }
 
 if (preg_match('/gif/',$system[1])){
 $orig_image = imagecreatefromgif($thumbnail_picture);
 }
 
 $newwidth = $thumbnail_width;
 $newheight = $thumbnail_height;
 
 $sm_image = imagecreatetruecolor($newwidth, $newheight) or die ("Cannot Initialize GD Image");
 
 imagecopyresampled($sm_image, $orig_image, 0, 0, 0, 0, $newwidth, $newheight, 
 imagesx($orig_image), imagesy($orig_image)); 
 
 imagejpeg($sm_image,'',90); 
 imagedestroy($sm_image); 
 imagedestroy($orig_image);


 ?>

اما در مورد گالری عکس من همچنان از 4images Gallery استفاده و برای همه توصیه میکنم.

ایمان
 

جدیدترین ارسال ها

بالا