2010-02-03 11 views
11

क्या किसी को पता है कि एनिमेटेड जीआईएफ दो अलग-अलग जेपीईजी फाइलों से उत्पन्न करना संभव है, एक्स सेकंड के लिए एक छवि प्रदर्शित करना, दूसरा, और इसी तरह ..?PHP - दो जेपीईजी छवियों से सरल एनिमेटेड जीआईएफ बनाएं?

किसी भी सलाह की सराहना की।

धन्यवाद।

उत्तर

6

मानक जीडी फ़ंक्शंस का उपयोग करना संभव नहीं है जो PHP के साथ पूर्व-पैक आते हैं।

इसके लिए class on phpclasses.org है। मैंने इसे कभी भी इस्तेमाल नहीं किया है, लेकिन इसका उपयोग कई अन्य पैकेजों द्वारा किया जाता है।

वैकल्पिक रूप से, यदि आपके पास तक PHP से पहुंच है, तो MagickWand लाइब्रेरी या कमांड लाइन का उपयोग करके, इसका उपयोग करें। ImageMagick के साथ, यह कोई समस्या नहीं है।

+0

** phpclasses.org ** कोड एक्सेस करने के लिए एक दुःस्वप्न है और इसके लिए इनपुट फाइलें जीआईएफ फाइलें होनी चाहिए। यह जेपीईजी फाइलों के लिए काम नहीं करता है ...: -/ –

+0

आप इस इनपुट का उपयोग करके अपने इनपुट जेपीईजी छवियों को (स्थिर) जीआईएफ छवियों में परिवर्तित कर सकते हैं SO SO प्रश्न: https://stackoverflow.com/a/755843/1617737 –

3

यह जी.डी. के साथ नहीं किया जा सकता है लेकिन मैं इसके लिए एक महान पुस्तकालय पाया। हालांकि यह थोड़ा जटिल है, इसलिए यहां लाइब्रेरी का एक लिंक है जो एनिमेटेड gifs php के साथ बनाता है। यह बताता है कि इसका पूरी तरह से उपयोग कैसे करें। http://www.phpclasses.org/package/3163-PHP-Generate-GIF-animations-from-a-set-of-GIF-images.html

चौड़ाई और ऊंचाई के लिए गति 900 के लिए 2 चित्रों का चयन करें और 100 लिखें। यह उन्हें एनिमेटेड gif स्लाइड शो में रखेगा। आप इसे का संदर्भ पहली लिंक पर पाया GIFEncoder वर्ग देख

<?php 
if(isset($_POST['speed'])) 
{ 
    header('Content-type: image/gif'); 
    if(isset($_POST['download'])){ 
    header('Content-Disposition: attachment; filename="animated.gif"'); 
    } 
    include('GIFEncoder.class.php'); 
    function frame($image){ 
     ob_start(); 
     imagegif($image); 
     global $frames, $framed; 
     $frames[]=ob_get_contents(); 
     $framed[]=$_POST['speed']; 
     ob_end_clean(); 
    } 
    foreach ($_FILES["images"]["error"] as $key => $error) 
    { 
     if ($error == UPLOAD_ERR_OK) 
     { 
      $tmp_name = $_FILES["images"]["tmp_name"][$key]; 
      $im = imagecreatefromstring(file_get_contents($tmp_name)); 
      $resized = imagecreatetruecolor($_POST['width'],$_POST['height']); 
      imagecopyresized($resized, $im, 0, 0, 0, 0, $_POST['width'], $_POST['height'], imagesx($im), imagesy($im)); 
      frame($resized); 
     } 
    } 
    $gif = new GIFEncoder($frames,$framed,0,2,0,0,0,'bin'); 
    echo $gif->GetAnimation(); 
} 
?> 
<form action="" method="post" enctype="multipart/form-data"> 
<script src="http://code.jquery.com/jquery-latest.js"></script> 
<script src="jquery.MultiFile.js"></script> 
<script src="jquery.placeholder.js"></script> 
<input type="file" name="images[]" class="multi" /> 
<script> 
    $(function(){ 
     $('input[placeholder], textarea[placeholder]').placeholder(); 
    }); 
</script> 
    <SCRIPT language=Javascript> 
     <!-- 
     function isNumberKey(evt) 
     { 
     var charCode = (evt.which) ? evt.which : event.keyCode 
     if (charCode > 31 && (charCode < 48 || charCode > 57)) 
      return false; 

     return true; 
     } 
     //--> 
    </SCRIPT> 
<input name="speed" maxlength="10" type="text" placeholder="Speed of frames in ms" onkeypress="return isNumberKey(event)"> 
<input name="width" maxlength="4" type="text" placeholder="Width" onkeypress="return isNumberKey(event)"> 
<input name="height" maxlength="4" type="text" placeholder="Height" onkeypress="return isNumberKey(event)"> 
<input type="submit" name="download" value="Download!"> 
<input type="submit" name="preview" value="Preview!"> 
</form> 

:

यहाँ है कि स्क्रिप्ट के लिए कोड है। यह कुछ जावास्क्रिप्ट सत्यापन और jQuery मल्टीप्लोड का भी उपयोग करता है।

नोट: यह प्रश्न पहले से ही पूछे जा चुके हैं।

+0

आपके वास्तव में अच्छे उदाहरण के लिए धन्यवाद! – Roy

+0

@Tom जब मैंने इस कोड को वापस करने की कोशिश की जैसे त्रुटि "प्रदर्शित नहीं किया जा सकता क्योंकि इसमें त्रुटियां हैं।" क्या आप मेरी मदद कर सकते हैं। – Jalpa

7

एक अच्छा, त्वरित और अधिक हालिया समाधान के लिए, this SO answer देखें।

इसके हालिया समाधान के लिए, here is my fork, इसमें कई छोटे फिक्स & सुधारों के साथ। एक वास्तविक आवेदन से यह का एक उदाहरण:

$anim = new GifCreator\AnimGif(); 

$gif = $anim->create($image_files); 
//file_put_contents("test.gif", $gif); 

header("Content-type: image/gif"); 
echo $gif; 

(GD2 साथ PHP5.3 की आवश्यकता है।)

उदाहरण है कि PHP 5.6 और जी.डी. 2.4.11 के साथ काम करता है:

require_once "AnimGif.php"; 

/* 
* Create an array containing file paths, resource var (initialized with imagecreatefromXXX), 
* image URLs or even binary code from image files. 
* All sorted in order to appear. 
*/ 
$image_files = array(
    //imagecreatefrompng("/../images/pic1.png"), // Resource var 
    //"/../images/pic2.png", // Image file path 
    //file_get_contents("/../images/pic3.jpg"), // Binary source code 
    'https://yt3.ggpht.com/-KxeE9Hu93eE/AAAAAAAAAAI/AAAAAAAAAAA/D-DB1Umuimk/s100-c-k-no-mo-rj-c0xffffff/photo.jpg', // URL 
    'https://media.licdn.com/mpr/mpr/shrinknp_100_100/AAEAAQAAAAAAAAloAAAAJDRkZGY2MWZmLTM1NDYtNDBhOS04MjYwLWNkM2UzYjdiZGZmMA.png', // URL 
    'http://is5.mzstatic.com/image/thumb/Purple128/v4/e4/63/e7/e463e779-e6d0-0c3d-3ec1-97fdbaae230a/source/100x100bb.jpg' // URL 
); 

/* 
* Create an array containing the duration (in millisecond) of each frame. 
*/ 
$durations_millis = array(
    1000, 
    2000, 
    3000 
); 

/* 
* Fix durations. 
*/ 
$durations = array(); 
for ($i = 0; $i < count($durations_millis); $i++) { 
    $durations[$i] = $durations_millis[$i]/10; 
} 

/* 
* Specify number of loops. (0 = infinite looping.) 
*/ 
$num_loops = 0; 

/* 
* Create gif object. 
*/ 
$anim_gif = new GifCreator\AnimGif(); 
$gif_object = $anim_gif->create($image_files, $durations, $num_loops); 

/* 
* Get the animated GIF binary. 
*/ 
$gif_binary = $gif_object->get(); 

/* 
* Set the file name of the saved/returned animated GIF. 
*/ 
$file_name = "animated.gif"; 

/* 
* Optionally, save animated GIF in a folder as a GIF: 
*/ 
//file_put_contents($file_name, $gif_binary); 

/* 
* Optionally, return the animated GIF to client. 
*/ 
header("Content-type: image/gif"); 
header('Content-Disposition: filename="' . $file_name . '"'); // Optional 
echo $gif_binary; 

/* 
* All done. 
*/ 
exit; 
+0

यह मेरे लिए काम नहीं करता है (जीडी 2.4.11 के साथ PHP5.6)। बस मुझे 'छवि' देता है ..."प्रदर्शित नहीं किया जा सकता है क्योंकि इसमें त्रुटियां हैं। –

+1

@ प्रतिबंध-जियोइंजिनियरिंग, इसे इंगित करने के लिए धन्यवाद। (ठीक है, कुछ भी संभव है, क्योंकि PHP5.6 तब मौजूद नहीं था।) एक संभावित फ़िक्स को कोड में अभी विलय कर दिया गया है वहां; कृपया पुनः प्रयास करें, और यदि समस्या बनी हुई है, तो कृपया गिटहब पर प्रोजेक्ट को कोई समस्या सबमिट करें, ताकि इसे ठीक से संबोधित किया जा सके। –

+0

इसके लिए धन्यवाद। अभी अपना काम कोड कोड स्निपेट के साथ अपडेट किया है। –

संबंधित मुद्दे