Forum Moderators: open
1. <a href="xxx"><img src="xxx" ...></a>
2. <a href="xxx"><img src="xxx" ...></a><br>Tile
3. <a href="xxx"><img src="xxx" ...><br>Tile</a>
4. <img src="xxx" ...><br><a href="xxx">Tile</a>
<picture>
<source media="(min-width: 680px)" srcset="big-widget.jpg">
<source media="(min-width: 460px)" srcset="small-widget.jpg">
<img src="widget.jpg" alt="Widgets" style="width:auto;">
</picture> <a target="new" href="/directory/image-file.jpg" title="XX" class="XX" rel="XX"><img alt="XX" src="../directory/resize.php?path=../directory/image-file.jpg" class="XX"></a> <?
$thumbsize = 100;
$imagesource = $_GET['path'];
$filetype = substr($imagesource,strlen($imagesource)-4,4);
$filetype = strtolower($filetype);
if($filetype == ".gif") $image = imagecreatefromgif($imagesource);
if($filetype == ".jpg") $image = imagecreatefromjpeg($imagesource);
if($filetype == ".png") $image = imagecreatefrompng($imagesource);
if (!$image) die();
$imagewidth = imagesx($image);
$imageheight = imagesy($image);
if ($imagewidth >= $imageheight) {
$thumbwidth = $thumbsize;
$factor = $thumbsize / $imagewidth;
$thumbheight = $imageheight * $factor;
}
if ($imageheight >= $imagewidth) {
$thumbheight = $thumbsize;
$factor = $thumbsize / $imageheight;
$thumbwidth = $imagewidth * $factor;
}
$thumb = imagecreatetruecolor($thumbwidth,$thumbheight);
imagecopyresized($thumb, $image, 0, 0, 0, 0, $thumbwidth, $thumbheight, $imagewidth, $imageheight);
imagejpeg($thumb);
imagedestroy($image);
imagedestroy($thumb);
?>
Change thumbsize to whatever you like. This is the largest side. resize.php
if ($imagewidth > $imageheight) {
$thumbwidth = $thumbsize;
$factor = $thumbsize / $imagewidth;
$thumbheight = $imageheight * $factor;
} elseif ($imageheight > $imagewidth) {
$thumbheight = $thumbsize;
$factor = $thumbsize / $imageheight;
$thumbwidth = $imagewidth * $factor;
} else {
$thumbwidth = $thumbsize;
$thumbheight = $thumbsize;
} This also serves to preload the full size image making it fast.