Hey, i am basically dynamically displaying images onto a page using PHP, the problem is i need them to displayed at a much smaller size and in proportion. here is a snippet of the code. echo '<a href="'. $auction_link .'"><img src='; echo ((!empty($main_image)) ? 'thumbnail.php?pic=' . $main_image . '&w=' . $layout['hpfeat_width'] . '&sq=Y' : 'themes/' . $setts['default_theme'] . '/img/system/noimg.gif'); echo '" height="80" width="60" border="0" alt="' .$item_details[$counter]['name'] . '"></a><br><br>'; Code (markup): as you can see at the moment to resize the image i am having to add in the height="80" width="60" which means that some images are totally out of proporotion. can anyone think of a little hack around this?
Usually I use this function: $sSource - file-source $sDest - file-destination $iMaxX - max width $iMaxY - max height $iRGB - the color of filling $iQuality - the quality of jpg image, that we get as a result */ function SaveResized ($sSource, $sDest, $iMaxX, $iMaxY, $iRGB=0xFFFFFF, $iQuality=80){ if (!file_exists($sSource)) return -1; //file not found $aImgSize = getimagesize($sSource); if ($aImgSize === false) return -2; //getimgsize error $sMime = strtolower(substr($aImgSize['mime'], strpos($aImgSize['mime'], '/')+1)); $fcImageCreateFrom = "imagecreatefrom" . $sMime; if (!function_exists($fcImageCreateFrom)) return -3; //unknown format $fXRatio = $iMaxX / $aImgSize[0]; $fYRatio = $iMaxY / $aImgSize[1]; $fRatio = min($fXRatio, $fYRatio); $fUseRatio = ($fXRatio == $fRatio); $iNewWidth = $fUseRatio ? $iMaxX : floor($aImgSize[0] * $fRatio); $iNewHeight = !$fUseRatio ? $iMaxY : floor($aImgSize[1] * $fRatio); $iNewLeft = $fUseRatio ? 0 : floor(($iMaxX - $iNewWidth) / 2); $iNewTop = !$fUseRatio ? 0 : floor(($iMaxY - $iNewHeight) / 2); $rImg = $fcImageCreateFrom($sSource); $rImgDest = imagecreatetruecolor($iMaxX, $iMaxY); imagefill($rImgDest, 0, 0, $iRGB); imagecopyresampled($rImgDest, $rImg, $iNewLeft, $iNewTop, 0, 0, $iNewWidth, $iNewHeight, $aImgSize[0], $aImgSize[1]); imagejpeg($rImgDest, $sDest, $iQuality); imagedestroy($rImg); imagedestroy($rImgDest); return true; } PHP:
OK. Here is the example of using this function: $myfil =$_FILES['photo']['tmp_name']; if (is_uploaded_file($myfil)) SaveResized ($myfil, "../images/content/brand_img$id.jpg",89, 30); PHP:
Oops! I mean this structure $iRGB - the color of filling $iQuality - the quality of jpg image, that we get as a result PHP:
Oops! If i need to solve this is the solution $iRGB='e8edf0'; $iQuality=80; Code (markup): BTW: My Job is Not Programming or 24 Hours dedicated Helping! If you know also Post your Solution! Also here is another one http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php