Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can try this function.</p> <pre><code>function thumb($file, $save, $width, $height) { @unlink($save); if (!$infos = @getimagesize($file)) { return false; } $iWidth = $infos[0]; $iHeight = $infos[1]; $iRatioW = $width / $iWidth; $iRatioH = $height / $iHeight; $iNewW = $width; $iNewH=($iHeight/$iWidth)*$iNewW; //$iNewH = $height; //Don't resize images which are smaller than thumbs if ($infos[0] &lt; $width &amp;&amp; $infos[1] &lt; $height) { $iNewW = $infos[0]; $iNewH = $infos[1]; } if($infos[2] == 1) { $imgA = imagecreatefromgif($file); $imgB = imagecreate($iNewW,$iNewH); if(function_exists('imagecolorsforindex') &amp;&amp; function_exists('imagecolortransparent')) { $transcolorindex = imagecolortransparent($imgA); //transparent color exists if($transcolorindex &gt;= 0 ) { $transcolor = imagecolorsforindex($imgA, $transcolorindex); $transcolorindex = imagecolorallocate($imgB, $transcolor['red'], $transcolor['green'], $transcolor['blue']); imagefill($imgB, 0, 0, $transcolorindex); imagecolortransparent($imgB, $transcolorindex); //fill white } else { $whitecolorindex = @imagecolorallocate($imgB, 255, 255, 255); imagefill($imgB, 0, 0, $whitecolorindex); } //fill white } else { $whitecolorindex = imagecolorallocate($imgB, 255, 255, 255); imagefill($imgB, 0, 0, $whitecolorindex); } imagecopyresampled($imgB, $imgA, 0, 0, 0, 0, $iNewW, $iNewH, $infos[0], $infos[1]); imagegif($imgB, $save); } elseif($infos[2] == 2) { $imgA = imagecreatefromjpeg($file); $imgB = imagecreatetruecolor($iNewW,$iNewH); imagecopyresampled($imgB, $imgA, 0, 0, 0, 0, $iNewW, $iNewH, $infos[0], $infos[1]); imagejpeg($imgB, $save); } elseif($infos[2] == 3) { /* * Image is typ png */ $imgA = imagecreatefrompng($file); $imgB = imagecreatetruecolor($iNewW, $iNewH); imagealphablending($imgB, false); imagecopyresampled($imgB, $imgA, 0, 0, 0, 0, $iNewW, $iNewH, $infos[0], $infos[1]); imagesavealpha($imgB, true); imagepng($imgB, $save); } else { return false; } return true; } thumb($source,$target_full_path,'337','208'); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload