खोज…


पहला चरण

स्थापना

डेबियन आधारित प्रणालियों पर उपयुक्त का उपयोग करना

sudo apt-get install php5-imagick

OSX / macOs पर Homebrew का उपयोग करना

brew install imagemagick

brew विधि का उपयोग कर स्थापित निर्भरता देखने के लिए, brewformulas.org/Imagemagick पर जाएं

बाइनरी रिलीज का उपयोग करना

Imagemagick वेबसाइट पर निर्देश।

प्रयोग

<?php

$imagen = new Imagick('imagen.jpg');
$imagen->thumbnailImage(100, 0); 
//if you put 0 in the parameter aspect ratio is maintained

echo $imagen;

?>

छवि को बेस 64 स्ट्रिंग में बदलें

यह उदाहरण है कि किसी छवि को बेस 64 स्ट्रिंग (यानी एक स्ट्रिंग जिसे आप सीधे एक img टैग की src विशेषता में उपयोग कर सकते हैं) में बदल सकते हैं। यह उदाहरण विशेष रूप से इमेजिक लाइब्रेरी का उपयोग करता है (अन्य उपलब्ध हैं, जैसे जीडी के रूप में भी)।

<?php
/**
 * This loads in the file, image.jpg for manipulation. 
 * The filename path is releative to the .php file containing this code, so
 * in this example, image.jpg should live in the same directory as our script.
 */
$img = new Imagick('image.jpg');

/**
 * This resizes the image, to the given size in the form of width, height.
 * If you want to change the resolution of the image, rather than the size
 * then $img->resampleimage(320, 240) would be the right function to use.
 *
 * Note that for the second parameter, you can set it to 0 to maintain the
 * aspect ratio of the original image.
 */
$img->resizeImage(320, 240);

/**
 * This returns the unencoded string representation of the image
 */
$imgBuff = $img->getimageblob();

/**
 * This clears the image.jpg resource from our $img object and destroys the
 * object. Thus, freeing the system resources allocated for doing our image
 * manipulation.
 */
$img->clear(); 

/**
 * This creates the base64 encoded version of our unencoded string from
 * earlier. It is then output as an image to the page.
 * 
 * Note, that in the src attribute, the image/jpeg part may change based on
 * the image type you're using (i.e. png, jpg etc).
 */
$img = base64_encode($imgBuff);
echo "<img alt='Embedded Image' src='data:image/jpeg;base64,$img' />";


Modified text is an extract of the original Stack Overflow Documentation
के तहत लाइसेंस प्राप्त है CC BY-SA 3.0
से संबद्ध नहीं है Stack Overflow