آموزش های این وب سایت به صورت رایگان در دسترس است. اطلاعات بیشتر
مشکل عدم دسترسی خریداران پیشین به برخی آموزش ها برطرف شد
بروز خطا
   [message]
اشتراک در سوال
رای ها
[dataList]

دلیل کار نکردن imagecreatefromjpeg ?

Mato  5 سال پیش  5 سال پیش
0 0

با سلام.

در قسمت آپلود عکس، فانکشن

imagecreatefrompng

کارکرد صحیحی دارد ولی فانکشن

imagecreatefromjpeg

به نظر شما مشکل از کجاست؟

با تشکر فراوان

 
 برای این سوال 1 پاسخ وجود دارد. مشاهده پاسخ صحیح
پاسخ به سوال 
Mato  5 سال پیش
+2 0

 پاسخ صحیح
function saveImage($keyword,$usedPath,$Id,$newWidth,$newHeight){
$file=$_FILES[$keyword]['tmp_name']; // a address of first location for file after upload
$ext=fetchImgExt($keyword);
$originalPath = getcwd() . "/" . $usedPath . "/original/" . $Id . $ext;
copy($file, $originalPath);

if($ext=='.jpeg'){$ext='.jpg';}
$thumbPath = getcwd() . "/" . $usedPath . "/" . $Id . $ext;

resizeImage($originalPath,$newWidth,$newHeight,$thumbPath);
}





function fetchImgExt($imgPostKey) {
$ext = $_FILES[$imgPostKey]['type']; // extension of file. example : image/png image/jpg ...
$ext = str_replace('image/', '.', $ext);
return $ext;
}





function resizeImage($sourcePath,$newWidth,$newHeight=null,$destination) {

$parts = explode(".", $sourcePath);
$ext = $parts[count($parts) - 1];

if ($ext == 'png') {
$sourceImage = imagecreatefrompng($sourcePath);
}

if ($ext == 'jpeg') {
$sourceImage = imagecreatefromjpeg($sourcePath);
}

list($srcWidth, $srcHeight) = getimagesize($sourcePath);
$ratio = getImageRatio($sourcePath);

if ($newWidth == 0) {
$newWidth = $newHeight / $ratio;
}

if ($newHeight == 0) {
$newHeight = $newWidth * $ratio;
}

$destinationImage = imagecreatetruecolor($newWidth, $newHeight);
imagecopyresampled($destinationImage, $sourceImage, 0, 0, 0, 0, $newWidth, $newHeight, $srcWidth, $srcHeight);


if ($destination == null) {
header("Content-Type: image/jpeg");

if ($ext == 'png') {
imagepng($destinationImage, null, 9);
}

if ($ext == 'jpeg') {
imagejpeg($destinationImage, null, 100);
}


} else {
if ($ext == 'png') {
imagepng($destinationImage, $destination,9);
}

if ($ext == 'jpeg') {
imagejpeg($destinationImage, $destination,100);
}

}

}





function getImageRatio($sourcePath){
list($width,$height)=getimagesize($sourcePath);
$imageRatio=$height/$width;
return $imageRatio;
}

پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .