imagecreatefromjpeg() PHP में एक इनबिल्ट फ़ंक्शन है जिसका उपयोग JPEG फ़ाइल से एक नई छवि बनाने के लिए किया जाता है। यह दिए गए फ़ाइल नाम से प्राप्त छवि का प्रतिनिधित्व करने वाला एक छवि पहचानकर्ता देता है।
सिंटैक्स
resource imagecreatefromjpeg(string $filename)
पैरामीटर
imagecreatefromjpeg() केवल एक पैरामीटर का उपयोग करता है, $filename , जिसमें छवि का नाम या JPEG छवि का पथ होता है।
वापसी मूल्य
imagecreatefromjpeg() सफलता पर एक छवि संसाधन पहचानकर्ता देता है, और यह गलत पर एक त्रुटि देता है।
उदाहरण 1
<?php
// Load an image from local drive/file
$img = imagecreatefromjpeg('C:\xampp\htdocs\test\1.jpeg');
// it will show the loaded image in the browser
header('Content-type: image/jpg');
imagejpeg($img);
imagedestroy($img);
?> आउटपुट

उदाहरण 2
<?php
// Load a JPEG image from local drive/file
$img = imagecreatefromjpeg('C:\xampp\htdocs\test\1(a).jpeg');
// Flip the image
imageflip($img, 1);
// Save the GIF image in the given path.
imagejpeg($img,'C:\xampp\htdocs\test\1(b).png');
imagedestroy($img);
?> इनपुट छवि

आउटपुट छवि

स्पष्टीकरण - उदाहरण 2 में, हमने imagecreatefromjpeg() का उपयोग करके स्थानीय पथ से jpeg छवि लोड की है। समारोह। इसके बाद, हमने इमेज फ्लिप करने के लिए इमेजफ्लिप () फंक्शन का इस्तेमाल किया।
उदाहरण 3 - JPEG छवि लोड करते समय त्रुटियों को संभालना
<?php
function LoadJpeg($imgname) {
/* Attempt to open */
$im = @imagecreatefromjpeg($imgname);
/* See if it failed */
if(!$im) {
/* Create a black image */
$im = imagecreatetruecolor(700, 300);
$bgc = imagecolorallocate($im, 0, 0, 255);
$tc = imagecolorallocate($im, 255,255, 255);
imagefilledrectangle($im, 0, 0, 700, 300, $bgc);
/* Output an error message */
imagestring($im, 20, 80, 80, 'Error loading ' . $imgname, $tc);
}
return $im;
}
header('Content-Type: image/jpeg');
$img = LoadJpeg('bogus.image');
imagejpeg($img);
imagedestroy($img);
?> आउटपुट
