الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

تشفير الصورة

مغلق
بدأه MD_Programmer في 17 يونيو 2005 · 2 رد · 623 مشاهدة · في منتدى تطوير المواقع بـ PHP
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمة الله...

أرجو مساعدتي في مشكلة تعترضني وهي تهمني كثيرا: :unsure:

تتضمن التعامل مع الصورة (قراءة وتشفير بياناتها)، يتم أولاً قراءة بايتات الصورة وتحويلها إلى ملف نصي أقصد به ملف أصفار وواحدات أي التخزين لبيانات الصورة ضمن الملف وفق النظام الثنائي (من ثم سيسهل تحويله إلى النظام الست عشري)، وكل ذلك مطلوب وفق لغة PHP ، علماً أنني قد بحثت كثيراً ضمن المواقع عن هذه الفكرة وتوصلت إلى أفكار عن التحويل إلى شيفرة أسكي أو النظام الست عشري ولكن كان ذلك مجرد ذكر لأفكار عامة وليست شيفرة واضحة تعالج الصورة وتشفيرها وفق النظام الثنائي أو الست عشري..... مع شكري للجميع...وتمنياتي بمزيد من التألق والنجاح للموقع..

#2

شوف كدة دة

دة كلاس عملته انهاردة بيقرا الصور زى مانت قولت و بيحولها لـ ASCII

حيشتغل معاك إن شاء الله على php 4.x.x او php 5.x.x بدون مشاكل

<?php

class Shref_ASCIIimg
{

 /*
  this is a simple class can convert an image (to & from) ASCII
  and can save the final data in a new file if you want.
  *it can be modified to  do more tasks in many ways .

  programmer : Ahmed Shref
  country    : Egypt
  city       : Alexandria
  Date       : 29 jun 2005
 */

 /*
 *prototype*
 parameters :
  the first parameter   :is the the saved data file path .
  the seconde parameter : tells the class if you want convert
                          ( to or from ) ASCII
                          to   : mean convert to ASCII
                          from : mean convert from ASCII to normal char.
  the third parameter   : [optional] the file path you want the final
                          data to be saved in .
 */

 /*
 example 1 :  will convert an image to ASCII and save it in a new file
 <?
  $test = new Shref_ASCIIimg('S.gif', 'to', 'ASCIIdata.txt');
 ?>

 example 2 : convert ASCII data to normal chars and print it to screen
 <?
 $test2 = new Shref_ASCIIimg('ASCIIdata.txt', 'from');
 print $test2->data;
 ?>
 add <?php header("content-type: image/gif");  ?> if it was an image
 */



 var $path     ; // the file path

 var $data  = ""; // the converted data will be here

 var $erorr = FALSE;

 /* in Shref_ASCIIimg constructor .
     #** $path of the file .

     #** $operation : --->
       ->* to (convert to ASCII)
       ->* from (convert from ASCII to char).

     #** $saveTo  is the file where you want to save the data in
 */
 function Shref_ASCIIimg($path ,$operation = "to",$saveTo = false)
 {
 //declare vars
 $this->path      = $path     ;
 $this->operation = $operation;
 $this->saveTo    = $saveTo   ;

 //check the operating way
  switch ($this->operation)
         { //convert image to ASCII
           case "to":
            $this->toASCII();
           break;
           // convert from ASCII to char
           case "from":
            $this->tochar();
           break;
           //by default will convert to ASCII
           default:
            $this->toASCII();
         }//switch


  //check if the data will be saved to file or not
  !$this->saveTo? $this->saveTo="" : $this->save()     ;

  //check for erorrs
  if($this->erorr)
   print $this->erorr;
 }

 /*
   void toAScii()
   no parameters
   convert the file contents to ASCII
 */
  function toASCII()
  {
   $this->fileHolder = @fopen($this->path,"r");
   if(!$this->fileHolder)
     { return $this->erorr="filed to open file";}

     do
     {
     $this->char     = fread($this->fileHolder, 1);
     $this->data    .= ord($this->char)." ";
     }
     while(!feof($this->fileHolder));

   fclose($this->fileHolder);
  }

  /*
   void tochar()
   no parameters
   convert the file contents from ASCII to normal chars
 */
  function tochar()
  {
   $this->fileHolder = @fopen($this->path,"r");
   if(!$this->fileHolder)
     { return $this->erorr="filed to open file";}

   $this->rFile = "";
      while (!feof($this->fileHolder))
            {
             $this->rFile   .= fread($this->fileHolder,2048);
            }//while

   fclose($this->fileHolder);

   $this->char = explode(" ",$this->rFile);

      foreach($this->char as $key=>$value)
             {
              $this->data .=chr($value);
             } //foreach
   }

   /*
     void save()
     no parameters
     saves the converted data to file
   */
   function save()
   {
    $this->fileHolder = @fopen($this->saveTo,"w");
   if(!$this->fileHolder)
     { return $this->erorr="filed to open file";}

    fwrite($this->fileHolder, $this->data);
    fclose($this->fileHolder);
    }

}//Shref_ASCIIimg

فى المرفقات ححط ملف فيه امثلة على استخدام الكلاس للى عايزه عموما

Shref_ASCIIimg.rar

Web Citizen

ShrefInLife.gif

__________

General blog : Shref In Life

#3

السلام عليكم ..

الله يجزيك كل خير أخي العزيز على جوابك.. غير ان موضوع تشفير الصورة وفق شيفرة أسكي لم يكن مجدياً في مشروعي الذي يتطلب مني إنجازه بسرعة ..

ولكني أعالج الآن موضوع تشفير الصورة وفق ألوانها أي تتم قراءة الصورة بيكسل بيكسل وكل بيكسل نقوم بأخذ تشفير أسكي المقابل للون هذا البيكسل ... ومازلت في الخطوة الأولى وهي قراءة بيكسلات الصورة ومعرفة اللون المقابل لكل بيكسل ...

فإن كنت قد تعاملت مسبقاً بهذا الموضوع ... أتمنى أن تساعدني ببعض الملاحظات والتوجيهات لأنني أجهل أسلوب المعالجة الصحيحة ...

مع شكري

هذا الموضوع مغلق.

مواضيع مشابهة