سؤال
هل من الممكن إنشاء صور باستخدام PHP (بدلاً من مجرد الارتباط بها عبر HTML) وإذا كان الأمر كذلك، فأين يجب أن أذهب أولاً للتعرف على شيء من هذا القبيل؟
المحلول
لكنني أفضل مكتبة جي دي - الدفع الأمثلة, ، وهذا المثال:
<?php
header ("Content-type: image/png");
$im = @imagecreatetruecolor(120, 20)
or die("Cannot Initialize new GD image stream");
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, "A Simple Text String", $text_color);
imagepng($im);
imagedestroy($im);
?>
النواتج:
(مصدر: php.net)
يرى imagecreatetruecolor.
نصائح أخرى
نعم هذا ممكن.أعتقد أن هناك مكتبات متعددة لتحقيق ذلك.الأكثر استخدامًا هو على الأرجح ImageMagick وهو في الواقع ليس خاصًا بـ PHP ولكنه يأتي مع روابط مناسبة.
أنظر أيضا في وثائق PHP.
الدفع جي دي.يحتوي على الكثير من الوظائف لإنشاء الصور ومعالجتها واستجوابها.يجب أن يتم تثبيت PHP الخاص بك باستخدام مكتبة GD التي ربما كانت كذلك.
للحصول على دروس تعليمية جيدة حول إنشاء الصور باستخدام PHP:
المدير العام - http://devzone.zend.com/node/view/id/1269
إيماج ماجيك - http://www.sitepoint.com/article/dynamic-images-imagemagick
MagickWand جيد جدًا لذلك أيضًا، وهو قوي جدًا.
http://www.bitweaver.org/doc/magickwand/index.html
سيلتقط هذا المقتطف صورة، ويكتب "الوردة" في Vera، أو أي خطوط متاحة، وينقل الصورة إلى المتصفح.
$drawing_wand=NewDrawingWand();
DrawSetFont($drawing_wand,"/usr/share/fonts/bitstream-vera/Vera.ttf");
DrawSetFontSize($drawing_wand,20);
DrawSetGravity($drawing_wand,MW_CenterGravity);
$pixel_wand=NewPixelWand();
PixelSetColor($pixel_wand,"white");
DrawSetFillColor($drawing_wand,$pixel_wand);
if (MagickAnnotateImage($magick_wand,$drawing_wand,0,0,0,"Rose") != 0) {
header("Content-type: image/jpeg");
MagickEchoImageBlob( $magick_wand );
} else {
echo MagickGetExceptionString($magick_wand);
}
يمكنك استخدام مكتبة gd بوظيفة مختلفة منها.وإنشاء صورة جيدة باستخدام الكود
header("Content-Type: image/png");
//try to create an image
$im = @imagecreate(800, 600)
or die("Cannot Initialize new GD image stream");
//set the background color of the image
$background_color = imagecolorallocate($im, 0xFF, 0xCC, 0xDD);
//set the color for the text
$text_color = imagecolorallocate($im, 133, 14, 91);
//adf the string to the image
imagestring($im, 5, 300, 300, "I'm a pretty picture:))", $text_color);
//outputs the image as png
imagepng($im);
//frees any memory associated with the image
imagedestroy($im);
اللون إلى سلبي
if(!file_exists('dw-negative.png')) {
$img = imagecreatefrompng('dw-manipulate-me.png');
imagefilter($img,IMG_FILTER_NEGATE);
imagepng($img,'db-negative.png');
imagedestroy($img);
}