मैं काफी उलझन में हूं कि पीडीजी छवियों का उपयोग जीडी लाइब्रेरी का उपयोग करके आकार में क्यों किया जाता है, मूल से आकार में बहुत बड़ा है।मूल छवि की तुलना में पीएनजी छवि का आकार इतना बड़ा क्यों है?
// create image from posted file
$src = imagecreatefrompng($file['tmp_name']);
// get original size of uploaded image
list($width,$height) = getimagesize($file['tmp_name']);
if($width>$maxImgWidth) {
// resize the image to maxImgWidth, maintain the original aspect ratio
$newwidth = $maxImgWidth;
$newheight=($height/$width)*$newwidth;
$newImage=imagecreatetruecolor($newwidth,$newheight);
// fill transparent with white
/*$white=imagecolorallocate($newImage, 255, 255, 255);
imagefill($newImage, 0, 0, $white);*/
// the following is to keep PNG's alpha channels
// turn off transparency blending temporarily
imagealphablending($newImage, false);
// Fill the image with transparent color
$color = imagecolorallocatealpha($newImage,255,255,255,127);
imagefill($newImage, 0, 0, $color);
// restore transparency blending
imagesavealpha($newImage, true);
// do the image resizing by copying from the original into $newImage image
imagecopyresampled($newImage,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
// write image to buffer and save in variable
ob_start(); // Stdout --> buffer
imagepng($newImage,NULL,5); // last parameter is compression 0-none 9-best (slow), see also http://www.php.net/manual/en/function.imagepng.php
$newImageToSave = ob_get_contents(); // store stdout in $newImageToSave
ob_end_clean(); // clear buffer
// remove images from php buffer
imagedestroy($src);
imagedestroy($newImage);
$resizedFlag = true;
}
तब मैं mysql डेटाबेस में ब्लॉब के रूप में $ newImageToSave बचाने:
इस कोड मैं छवि का आकार बदलने का उपयोग कर रहा है।
मैंने अल्फा चैनल को रोकने की कोशिश की और केवल सफेद पृष्ठभूमि सेट की, फ़ाइल आकार में कोई महत्वपूर्ण बदलाव नहीं हुआ। मैंने "संपीड़न" पैरामीटर (0 से 9) को सेट करने का प्रयास किया, लेकिन फिर मूल के बाद भी बड़ा।
उदाहरण
मैं ले लिया इस image (1058px * 1296px) और 900px * 1102px करने के लिए इसे आकार दिया।
मूल फ़ाइल:: 328 KB
पीएनजी (0): 3,79 एमबी
पीएनजी (5): 564 KB
पीएनजी (9): 503 KB
कोई टिप ये परिणाम हैं फ़ाइल आकार में छोटे आकार की छवि को कैसे प्राप्त किया जाए, इसकी सराहना की जाती है।
-
पुनश्च: मैंने सोचा कि यह बिट गहराई हो सकता है, लेकिन जैसा कि आप देख सकते हैं, उदाहरण के छवि के ऊपर, 32 बिट है, जबकि resized छवि 24 बिट है।
आप उपयोग कर रहे हैं '5' संपीड़न कारक के लिए। '9' आज़माएं और देखें कि क्या होता है। –
मुझे आश्चर्य है कि क्या आपका नया आयामी आकार संपीड़न को प्रभावी नहीं होने का कारण बन रहा है। यह देखना दिलचस्प होगा कि विभिन्न आकार आयाम किस फ़ाइल आकार में संपीड़ित होंगे। उदाहरण के लिए यदि लक्ष्य आयाम मूल आकार का एक आधा है, तो नया फ़ाइल आकार क्या है। –
@MarcB बस ऊपर देखें: पीएनजी (9): 503 केबी –