ورود

View Full Version : اسكریپت ریسایر تصاویر



clip2ni
شنبه 05 اسفند 1391, 18:34 عصر
با سلام

این كد تصاویر رو ریسایز میكنه اما برای تصویری با پسوند JPG یا png یا gif یا ... خرابه و درواقع فقط برای jpg كار میكند

لطفا كمكم كنید تا تصحیحش كنم

در واقع من دنبال اسكریپتی هستم كه جای timthumb.php استفاده كنم چرا كه این اسكریپت به شدت به cpu فشار میاره


<?php
$output_width =200;
$output_height=150;

$path = ( (isset($_REQUEST['path']))? $_REQUEST['path'] : "");
$size_arr = getimagesize($path);
if ($size_arr[2]==IMAGETYPE_GIF)
$image = imagecreatefromgif($path);
else if ($size_arr[2]==IMAGETYPE_JPEG)
$image = imagecreatefromjpeg($path);
else if ($size_arr[2]==IMAGETYPE_PNG)
$image = imagecreatefrompng($path);
else
die_default_image();

$tmpname = tempnam( sys_get_temp_dir() , "phptmp");

resize_image($tmpname, $image, $size_arr, $output_width, $output_height);

header('Content-Type: image/jpg');
header('Content-Disposition: inline; filename="'.basename($path).'"');
echo file_get_contents( $tmpname );
unlink( $tmpname );
die('');


function die_default_image()
{
//43byte 1x1 transparent pixel gif
header("content-type: image/gif");
echo base64_decode("R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAA ICRAEAOw==");
}

function resize_image($thumbname, $image, $size_arr, $max_width, $max_height)//maintain aspect ratio
{
$width = $max_width;
$height = $max_height;
list($width_orig, $height_orig, $img_type) = $size_arr;
$ratio_orig = $width_orig/$height_orig;
/*
if ($width/$height > $ratio_orig) {
$width = floor($height*$ratio_orig);
} else {
$height = floor($width/$ratio_orig);
}
*/
// Resample
$tempimg = imagecreatetruecolor($width, $height);
imagecopyresampled($tempimg, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
imagejpeg($tempimg, $thumbname, 80);
}

if ( !function_exists('sys_get_temp_dir')) {
function sys_get_temp_dir() {
if (!empty($_ENV['TMP'])) { return realpath($_ENV['TMP']); }
if (!empty($_ENV['TMPDIR'])) { return realpath( $_ENV['TMPDIR']); }
if (!empty($_ENV['TEMP'])) { return realpath( $_ENV['TEMP']); }
$tempfile=tempnam(uniqid(rand(),TRUE),'');
if (file_exists($tempfile)) {
unlink($tempfile);
return realpath(dirname($tempfile));
}
}
}
?>


اینك یك نمونه ارور

http://www.clip2ni.com/ww/resize_image.php?path=http://dl.clip2ni.com/91/10/khandeye%20footbal%201010.wmv.0000002694.JPG

soroush.r70
شنبه 05 اسفند 1391, 20:12 عصر
اینو تو تالار php بیان کن جوابتو می گیری

clip2ni
شنبه 05 اسفند 1391, 22:08 عصر
لطفا یكی از مدیرا انتقال بده

soroush.r70
یک شنبه 06 اسفند 1391, 06:35 صبح
تا انتقال بدن جوابتو بدم

فایل imgsize.php


<?php
header ("Content-type: image/jpeg");
/*
JPEG / PNG Image Resizer
Parameters (passed via URL):

img = path / url of jpeg or png image file

percent = if this is defined, image is resized by it's
value in percent (i.e. 50 to divide by 50 percent)

w = image width

h = image height

constrain = if this is parameter is passed and w and h are set
to a size value then the size of the resulting image
is constrained by whichever dimension is smaller

Requires the PHP GD Extension

Outputs the resulting image in JPEG Format

By: Michael John G. Lopez - www.sydel.net
Filename : imgsize.php
*/

$img = $_GET['img'];
$percent = $_GET['percent'];
$constrain = $_GET['constrain'];
$w = $_GET['w'];
$h = $_GET['h'];

// get image size of img
$x = @getimagesize($img);
// image width
$sw = $x[0];
// image height
$sh = $x[1];

if ($percent > 0) {
// calculate resized height and width if percent is defined
$percent = $percent * 0.01;
$w = $sw * $percent;
$h = $sh * $percent;
} else {
if (isset ($w) AND !isset ($h)) {
// autocompute height if only width is set
$h = (100 / ($sw / $w)) * .01;
$h = @round ($sh * $h);
} elseif (isset ($h) AND !isset ($w)) {
// autocompute width if only height is set
$w = (100 / ($sh / $h)) * .01;
$w = @round ($sw * $w);
} elseif (isset ($h) AND isset ($w) AND isset ($constrain)) {
// get the smaller resulting image dimension if both height
// and width are set and $constrain is also set
$hx = (100 / ($sw / $w)) * .01;
$hx = @round ($sh * $hx);

$wx = (100 / ($sh / $h)) * .01;
$wx = @round ($sw * $wx);

if ($hx < $h) {
$h = (100 / ($sw / $w)) * .01;
$h = @round ($sh * $h);
} else {
$w = (100 / ($sh / $h)) * .01;
$w = @round ($sw * $w);
}
}
}

$im = @ImageCreateFromJPEG ($img) or // Read JPEG Image
$im = @ImageCreateFromPNG ($img) or // or PNG Image
$im = @ImageCreateFromGIF ($img) or // or GIF Image
$im = false; // If image is not JPEG, PNG, or GIF

if (!$im) {
// We get errors from PHP's ImageCreate functions...
// So let's echo back the contents of the actual image.
readfile ($img);
} else {
// Create the resized image destination
$thumb = @ImageCreateTrueColor ($w, $h);
// Copy from image source, resize it, and paste to image destination
@ImageCopyResampled ($thumb, $im, 0, 0, 0, 0, $w, $h, $sw, $sh);
// Output resized image
@ImageJPEG ($thumb);
}
?>


طریقه استفاده


<img src="imgsize.php?w=557&h=457&img=name.jpg" />

clip2ni
یک شنبه 06 اسفند 1391, 10:06 صبح
عزیزم شما كه اسكریپت من رو تصحیح نكردی این اسكریپتی هم كه دادی ، ارور میده واسه نمایش

http://www.clip2ni.com/ww/resize_image.php?w=557&h=457&img=http://dl.clip2ni.com/91/10/khandeye%20footbal%201010.wmv.0000002694.JPG

clip2ni
یک شنبه 06 اسفند 1391, 10:10 صبح
البته این به نظر از اسكریپتی كه من دادم قوی تره و png و gif و jpg رو نمایش میده اما عكسی به آدرس زیر رو نشون نمیده و ارور میده


http://dl.clip2ni.com/91/10/khandeye footbal 1010.wmv.0000002694.JPG

اینم متن ارور :

The image “http://www.clip2ni.com/ww/resize_image.php?w=557&h=457&img=http://dl.clip2ni.com/91/10/khandeye%20footbal%201010.wmv.0000002694.JPG” cannot be displayed because it contains errors.
http://www.clip2ni.com/ww/resize_image.php?w=557&h=457&img=http://dl.clip2ni.com/91/10/khandeye%20footbal%201010.wmv.0000002694.JPG

clip2ni
یک شنبه 06 اسفند 1391, 19:55 عصر
كسی نبود؟:ناراحت:

البته فكر كنم مشكل space كه تو لینك عكسه !