Forum Moderators: not2easy
Our web format is 300 pixels wide. That's what we want the final uploaded photos to be.
Is there a process that we can use? Keep in mind that it's artistically and technologically clueless people who upload these images-- not us-- so it has to be idiot proof. And of course the original digital output from a given broker's camera may be anywhere from 640 X 480 on up. We never know.
This is a PHP/MySQL Linux site. I would appreciate anybody's experience or advice on this.
There are a number of means for resizing photos available to PHP, in the form of image processing libraries. These are GD1, GD2, imagemagick, and netbpm.
GD1 produces the least visually appealing results. I'd guess your software is using GD1 functions. Make a php info file - below:
<?php
phpinfo();
?>
See if under the heading 'gd' the 'gd version' is 2 or higher. If so, you can use gd2 functions.
Try replacing every occurrence of 'imagecreate(' with 'imagecreatetruecolor(' and you'll then be using the GD2 pallette, which is a lot richer.
Another possible culprit is the saving of the image with imagejpeg(). If there's a number at the end of the arguments of this function, that number determines the quality of the jpeg (lower number = lower quality, smaller size in K (though sometimes insignificantly smaller)). Hike this up to about 75 if it's in there - see [be2.php.net...] .
Feel free to sticky me on this matter or send code.
mincklerstraat:
Thanks for the info on GD2 and the imagejpeg() function. That looks promising. Since I'm about 80% designer and 20% developer and am only just now learning PHP/MySQL, I'm asking our developer partner to jump in on this string straight away.
Thank you both for your replies.
We would seem to have the suggested points covered.
We are using GD 2.0.12
The function that I am using seems to fulfill all the suggested solutions and yet we get poor results. I am currently asking for zero compression on the jpg.
Any additional thoughts on this would be greatly appreciated.
================== code =======================
resampimagejpg($tgt_im_ht,$tgt_im_wd,$fpath,$fpath,0);
function resampimagejpg($forcedwidth, $forcedheight, $sourcefile, $destfile, $imgcomp) {
$g_imgcomp=100-$imgcomp;
$g_srcfile=$sourcefile;
$g_dstfile=$destfile;
$g_fw=$forcedwidth;
$g_fh=$forcedheight;
if(file_exists($g_srcfile)) {
$g_is=getimagesize($g_srcfile);
if(($g_is[0]-$g_fw)>=($g_is[1]-$g_fh)) {
$g_iw=$g_fw;
$g_ih=($g_fw/$g_is[0])*$g_is[1];
}else{
$g_ih=$g_fh;
$g_iw=($g_ih/$g_is[1])*$g_is[0];
}
$img_src=imagecreatefromjpeg($g_srcfile);
$img_dst=imagecreatetruecolor($g_iw,$g_ih);
imagecopyresampled($img_dst, $img_src, 0, 0, 0, 0, $g_iw, $g_ih, $g_is[0], $g_is[1]);
imagejpeg($img_dst, $g_dstfile, $g_imgcomp);
imagedestroy($img_dst);
return true;
}else{
return false;
}
}