2011-10-15 10 views
10

अरबी मेरे पिछले संबंधित सवाल writting जबकि:त्रुटि छवि

php work with images : write complete word in arabic , ttf font

मेरे समस्या थी:

  • अगर मैं छवि यह प्रतीत होता है के रूप में د م ح ا
  • खैर में احمد लिखना चाहते हैं, मैंने इसे ठीक किया और अब आउटपुट: ا ح م د

इस समारोह का उपयोग करना:

function arab($word){ 

     $w = explode(' ',$word) ; 

     $f = array(array('ا','أ'),'ب','ت','ث','ج','ح','د','ذ','ر','ز','س','ش','ص','ض','ط','ظ','ع','غ','ف','ق','ك','ل','م','ن','ه','و','ى'); 

     $t = array(array('ا_','أ_'),'ب_','ت_','ث_','ج_','ح_','د_','ذ_','ر_','ز_','س_','ش_','ص_','ض_','ط_','ظ_','ع_','غ_','ف_','ق_','ك_','ل_','م_','ن_','ه_','و_','ى_'); 

     $my_arab = '' ; 

     foreach($w as $wo) 
     { 
      $r = array() ; 

      $wo = str_replace($f , $t ,$wo); 

      $ne = explode('_', $wo) ; 

      foreach($ne as $new) { 
       $new = str_replace('_','',$new) ; 
       array_unshift($r , $new); 
      } 

      $my_arab .= ' '.implode('',$r) ; 

     } 

    return trim($my_arab) ; 

} 

लेकिन नई समस्या है:

ا ح م د

(अलग पत्र) जहां यह होना चाहिए:

احمد

मैं कैसे ठीक कर सकते हैं इस?

+0

क्षमा करें, मुझे सवाल समझ में नहीं आता है।अगर आप 'احمد' को 'احمد' के रूप में दिखाना चाहते हैं, तो आप इसे इस फ़ंक्शन के माध्यम से क्यों रूट करते हैं? – JJJ

+0

क्योंकि यह 'ا ح م د' की तरह सही है लेकिन –

+0

अक्षरों के बीच की जगहों के साथ अरबी स्ट्रिंग को विचलित करने लगता है, '$ f' और' $ t' पंक्तियां मुद्रित के रूप में वैध वाक्यविन्यास नहीं हैं, अगर आप सी और पी में एक सामान्य संपादक वे वापस सामान्य पर आते हैं। – Victory

उत्तर

3

आप मैं इसे छवियों में फारसी लिखने के

<?php 
#---------------------------------------------------------------------- 
# Persian Image 1 
#---------------------------------------------------------------------- 
# Copyright (c) 2011 Saeed Arab Sheybani 
#---------------------------------------------------------------------- 
# This program is under the terms of the GENERAL PUBLIC LICENSE (GPL) 
# as published by the FREE SOFTWARE FOUNDATION. The GPL is available 
# through the world-wide-web at http://www.gnu.org/copyleft/gpl.html 
#---------------------------------------------------------------------- 
# Authors: Saeed Arab Sheybani <[email protected]> 
# Thanks to TCPDF project @ http://www.tecnick.com/ i use unicode_data.php and bidi.php from this site 
#---------------------------------------------------------------------- 

/** 
* A function to change persian or arabic text from its logical condition to visual 
* 
* @author  Saeed Arab Sheybani <[email protected]> 
* @param  string Main text you want to change it 
* @param  boolean Apply e'raab characters or not? default is true 
* @param  boolean Which encoding? default it "utf8" 
* @param  boolean Do you want to change special characters like "allah" or "lam+alef" or "lam+hamza", default is true 
*/ 
function Persian_image(&$str) 
{ 
    include_once('bidi.php'); 

    $text = explode("\n", $str); 

    $str = array(); 

    foreach($text as $line){ 
     $chars = bidi::utf8Bidi(bidi::UTF8StringToArray($line), 'R'); 
     $line = ''; 
     foreach($chars as $char){ 
      $line .= bidi::unichr($char); 
     } 

     $str[] = $line; 
    } 

    $str = implode("\n", $str); 
} 
+0

यह उपरोक्त समाधान की तुलना में मेरे लिए बहुत बेहतर काम करता है। एआर-पीएचपी के ऊपर दिए गए समाधान ने कुछ पात्रों को ट्रैश किया, विशेष रूप से गैर-पश्चिमी अंक जिन्हें एंड्रॉइड सिस्टम द्वारा प्रारूपित दिनांक द्वारा बनाया गया था। – blackjack75

2

मैं इस whitout किसी भी समस्या का प्रयोग किया जाता है का उपयोग बीड़ी कनवर्टर का उपयोग करना चाहिए: https://github.com/omid/Persian-Log2Vis

अद्यतन: मैं फारसी-Log2Vis काँटेदार और कुछ कोड बदलने के ठीक काम करने के लिए। अरबी वर्ण नहीं है खाते में जुड़ा ग्लिफ़ की प्रकृति ले पीछे की https://github.com/tahmasebi/Persian-Log2Vis

8

आपका तरीका है। हालांकि, के मुद्दे को हल करने के लिए यह एक मान्य चाल है PHP/GD स्वचालित रूप से आरटीएल भाषाओं अरबी की तरह समर्थन नहीं करता है।

आपको क्या करना है ar-php लाइब्रेरी का उपयोग करना है जो वास्तव में आपके इरादे से है।

सुनिश्चित करें अपने PHP फ़ाइल एन्कोडिंग यूनिकोड/UTF में है।
उदा। > खुला नोटपैड> रूप में सहेजें> UTF-8 के रूप में एन्कोडिंग:

<?php 
    // The text to draw 
    require('./I18N/Arabic.php'); 
    $Arabic = new I18N_Arabic('Glyphs'); 
    $font = './DroidNaskh-Bold.ttf'; 
    $text = $Arabic->utf8Glyphs('لغةٌ عربيّة'); 

    // Create the image 
    $im = imagecreatetruecolor(600, 300); 

    // Create some colors 
    $white = imagecolorallocate($im, 255, 255, 255); 
    $grey = imagecolorallocate($im, 128, 128, 128); 
    $black = imagecolorallocate($im, 0, 0, 0); 
    imagefilledrectangle($im, 0, 0, 599, 299, $white); 

    // Add the text 
    imagettftext($im, 50, 0, 90, 90, $black, $font, $text); 

    // Using imagepng() results in clearer text compared with imagejpeg() 
    imagepng($im, "./output_arabic_image.png"); 
    echo 'open: ./output_arabic_image.png'; 
    imagedestroy($im); 
?> 

आउटपुट:

enter image description here

PHP में अरबी टाइपोग्राफी के लिए

enter image description here

नमूना उपयोग imagettftext का उपयोग कर

+0

यदि कोई इसे लार्वेल के साथ एकीकृत करने के इच्छुक है, तो ** ** "classmap" अनुभाग ** के अंतर्गत, अपने ** composer.json ** पर फ़ाइल पथ जोड़ें। [अधिक जानकारी] (https://laracasts.com/discuss/channels/general-discussion/include-a-non-composer-lib?page=1) – emonik

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