PDA

View Full Version : مشکل با تغییر اندازه عکس هنگام آپلود



mhd.ghavam
چهارشنبه 12 مرداد 1390, 09:36 صبح
سلام دوستان عزیزم من از یک کد برای تغییر اندازه عکس هنگام آپلود استفاده می کردم و خوب هم کار می کرد، اما متأسفانه مجبور شدم که سرور رو عوض کنم و از سرور ویندوز استفاده کنم که از PHP هم پشتیبانی می کنه اما تو سرور جدید این کد کار نمی کنه و ارور میده و میگه که تابع Imagejpeg شناخته شده نیست لطفا کمکم کنید، یا اگر کد بهتری یا راه حل بهتری سراغ دارید بگید خیلی ممنوم خدا خیرتون بده

این هم از کد


function small_image_upload($img_tm,$name_i,$width,$height, $location)
{


// $name_i = basename($img_tm);

$format = explode(".",$name_i);
$format = end($format);
$format = strtolower($format);

switch ($format) {
case "jpg":
$img_m = ImageCreateFromjpeg($img_tm);
break;
case "gif":
$img_m = ImageCreateFromgif($img_tm);
break;
case "png":
$img_m = ImageCreateFrompng($img_tm);
break;
default:
$ch_err = 1;
return $name_i;
}
if(!$ch_err){
$width_orig = imageSx($img_m); $height_orig = imageSy($img_m);
// ================================================== ==============================
$cop = ImageCreateTrueColor($width_orig,$height_orig);
$cop = ImageCreateTrueColor($width,$height);
ImageCopyResampled($cop,$img_m,0,0,0,0,$width,$hei ght,$width_orig,$height_orig);
Imagejpeg($cop,$location,80);
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
return true; exit();
}
return false;
}

armsoftpc
چهارشنبه 12 مرداد 1390, 15:35 عصر
به نام خدا
با سلام
من یک کدی قبلا برای یک پروژه نوشتم ، که در یک فایل اون عکس را تغییر اندازه میدهد ، نمی دونم بدردتون می خوره یا نه!
اگر بدردتون خورد حتما در این باره بنویسید.
موفق باشید.:قلب:



<?php

$image = $_REQUEST['image'];
$max_width = $_REQUEST['max_width'];
$max_height = $_REQUEST['max_height'];

if (!$max_width)
$max_width = 80;
if (!$max_height)
$max_height = 60;

$size = GetImageSize($image);
$width = $size[0];
$height = $size[1];

$x_ratio = $max_width / $width;
$y_ratio = $max_height / $height;

if ( ($width <= $max_width) && ($height <= $max_height) ) {
$tn_width = $width;
$tn_height = $height;
}
else if (($x_ratio * $height) < $max_height) {
$tn_height = ceil($x_ratio * $height);
$tn_width = $max_width;
}
else {
$tn_width = ceil($y_ratio * $width);
$tn_height = $max_height;
}

$src = ImageCreateFromJpeg($image);
$dst = ImageCreate($tn_width,$tn_height);
ImageCopyResized($dst, $src, 0, 0, 0, 0,
$tn_width,$tn_height,$width,$height);
header('Content-type: image/jpeg');
ImageJpeg($dst, null, -1);
ImageDestroy($src);
ImageDestroy($dst);

?>

billgivz
پنج شنبه 13 مرداد 1390, 00:55 صبح
<?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&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&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&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();
?>

ali 888
یک شنبه 10 مهر 1390, 22:32 عصر
دوستان من با این کلاس class=highlight مشکل دارم,باید تعریفش کنم یا یه کلاس مشخصه؟