<?php
function createThumbnail($imageDirectory, $imageName, $thumbDirectory, $thumbWidth) {
$explode = explode(".", $imageName);
$filetype = $explode[1];
if ($filetype == 'jpg') {
$srcImg = imagecreatefromjpeg("$imageDirectory/$imageName");
} else
if ($filetype == 'jpeg') {
$srcImg = imagecreatefromjpeg("$imageDirectory/$imageName");
} else
if ($filetype == 'png') {
$srcImg = imagecreatefrompng("$imageDirectory/$imageName");
} else
if ($filetype == 'gif') {
$srcImg = imagecreatefromgif("$imageDirectory/$imageName");
}
$origWidth = imagesx($srcImg);
$origHeight = imagesy($srcImg);
$ratio = $origWidth/$thumbWidth;
$thumbHeight = $origHeight/$ratio;
$thumbImg = imagecreatetruecolor($thumbWidth, $thumbHeight);
imagecopyresized($thumbImg, $srcImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $origWidth, $origHeight);
if ($filetype == 'jpg') {
imagejpeg($thumbImg, "$thumbDirectory/$imageName");
} else
if ($filetype == 'jpeg') {
imagejpeg($thumbImg, "$thumbDirectory/$imageName");
} else
if ($filetype == 'png') {
imagepng($thumbImg, "$thumbDirectory/$imageName");
} else
if ($filetype == 'gif') {
imagegif($thumbImg, "$thumbDirectory/$imageName");
}
}
?>
यह एक बहुत अच्छी थंबनेल स्क्रिप्ट है =) यहां एक उदाहरण है:
$ पथ = उस फ़ोल्डर का पथ जहां मूल तस्वीर है। $ name = उस फ़ाइल का फ़ाइल नाम जिसे आप थंबनेल बनाना चाहते हैं। $ thumbpath = निर्देशिका का पथ जहां आप थंबनेल को सहेजना चाहते हैं। $ maxwidth = पीएक्स उदाहरण में थंबनेल की अधिकतम चौड़ाई। 100 (जो 100 पीएक्स होगा)।
createThumbnail($path, $name, $thumbpath, $maxwidth);
ध्यान दें कि क्या छवियाँ हैं पर निर्भर करता है, JPG हमेशा एक PNG तुलना में एक छोटे फ़ाइल आकार के लिए नहीं होगा, तो सुनिश्चित करें कि आप अपनी स्थिति के लिए सही उपयोग कर रहे हैं। http://lbrandy.com/blog/2008/10/my-first-and-last-webcomic/ – jimyi