ورود

توجه ! این یک نسخه آرشیو شده میباشد و در این حالت شما عکسی را مشاهده نمیکنید برای مشاهده کامل متن و عکسها بر روی لینک مقابل کلیک کنید : مشکل در کش شدن عکس



billgivz
January 30th, 2015, 20:33
سلام دوستان

من از کد زیر برای ریساز کردن عکس و کم حجم کردن عکس استفاده میکنم . مشکل این هست عکساا کش نمیشه !!

ممنون میشم راهنمایی کنید .




<?php
/*
image.php

A simple image resize script that resizes images given either a maxsize, maxheight or maxwidth

Usage
=====
-to resize an image to a max of 400px along the longest side
<img src="image.php?size=400&amp;file=filename.jpg" />

-to resize an image to a height of 400px (width will be kept to the right aspect ratio)
<img src="image.php?size=h400&amp;file=filename.jpg" />

-to resize an image to a width of 400px (height will be kept to the right aspect ratio)
<img src="image.php?size=w400&amp;file=filename.jpg" />

This script is very simple and should not be considered for production use. There are many image
resizing scripts available that have better error checking, support for other formats (this only
supports jpg) and have image caching. Cachine makes a HUGE difference to overall speed.

@author Harvey Kane harvey@harveykane.com

*/

/* Get information from Query String */
if (!isset($_GET['file']) || !isset($_GET['size'])) {
echo "Image variables not specified correctly";
exit();
}

$file = $_GET['file'];
$size = $_GET['size'];

/* Get image dimensions and ratio */
list($width, $height) = getimagesize($file);
$ratio = $width / $height;

/* Decide how we should resize image - fixed width or fixed height */
if (substr($size, 0, 1) == 'h') {
$type = 'fixedheight';
} elseif (substr($size, 0, 1) == 'w') {
$type = 'fixedwidth';
} elseif ($height > $width) {
$type = 'fixedheight';
} else {
$type = 'fixedwidth';
}

/* Calculate new dimensions */
if ($type == 'fixedheight') {
$new_width = floor(str_replace('h','',$size) * $ratio);
$new_height = str_replace('h','',$size);
} else {
$new_width = str_replace('w','',$size);
$new_height = floor(str_replace('w','',$size) / $ratio);
}

/* Resample */
$new_image = imagecreatetruecolor($new_width, $new_height);
$old_image = imagecreatefromjpeg($file);
imagecopyresampled($new_image, $old_image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

/* Output */
//header('Content-type: image/jpeg');
imagejpeg($new_image, null, 100);
exit();
?>

shahinmq
January 30th, 2015, 20:37
کد رو در htaccess اضافه کنید :

در ضمن کدتون هم در قالب کد قرار بدید نه نقل قول تا راحت تر خونده بشه



## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType text/javascript "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 30 days"
</IfModule>