<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Eric COURTIAL</title>
    <description>The latest articles on Forem by Eric COURTIAL (@ecourtial).</description>
    <link>https://forem.com/ecourtial</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F421273%2Fb3a29b7c-417b-4eec-8dc3-1d1a7e6a2fe7.jpeg</url>
      <title>Forem: Eric COURTIAL</title>
      <link>https://forem.com/ecourtial</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ecourtial"/>
    <language>en</language>
    <item>
      <title>Parse and edit a BMP file with PHP</title>
      <dc:creator>Eric COURTIAL</dc:creator>
      <pubDate>Thu, 11 Feb 2021 17:46:47 +0000</pubDate>
      <link>https://forem.com/ecourtial/parse-and-edit-a-bmp-file-with-php-j84</link>
      <guid>https://forem.com/ecourtial/parse-and-edit-a-bmp-file-with-php-j84</guid>
      <description>&lt;p&gt;I did not find any easy solution to open and parse a BMP file. For a personal project I had to perform this kind of operation, so I created a basic library, aggregating some tutorials and sources.&lt;/p&gt;

&lt;p&gt;Let's start with the installation, classic:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;composer require ecourtial/php-bmp-parser&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now we can easily open and parse the file. In the below example, I get the Red, Green, Blue and Hex value of the pixel located at x = 2, y = 0:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$service = new BmpService();&lt;br&gt;
$image = $service-&amp;gt;getImage('myBmpFile.bmp');&lt;br&gt;
echo $image-&amp;gt;getPixel(2, 0)-&amp;gt;getR();&lt;br&gt;
echo $image-&amp;gt;getPixel(2, 0)-&amp;gt;getG();&lt;br&gt;
echo $image-&amp;gt;getPixel(2, 0)-&amp;gt;getB();&lt;br&gt;
echo $image-&amp;gt;getPixel(2, 0)-&amp;gt;getHex();&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This operation is quite simple, and does not require any third party library or PHP extension.&lt;/p&gt;

&lt;p&gt;The library also allows basic editing, with some limitations though, and you will need this time the &lt;em&gt;gd&lt;/em&gt; PHP extension.&lt;/p&gt;

&lt;p&gt;In the below example, I want to edit the file previously opened and save it with another name. I change the color of one pixel, extends the size of the image (new pixels are white by default) and finally edit some of the newly added pixels.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$image-&amp;gt;setPath('myNewBmpFile.bmp);&lt;br&gt;
$image-&amp;gt;getPixel(0, 1)-&amp;gt;setR(0)-&amp;gt;setG(0)-&amp;gt;setB(126);&lt;br&gt;
$image-&amp;gt;setDimensions(3, 4);&lt;br&gt;
$image-&amp;gt;getPixel(0, 3)-&amp;gt;setR(200)-&amp;gt;setG(0)-&amp;gt;setB(200);&lt;br&gt;
$image-&amp;gt;getPixel(1, 3)-&amp;gt;setR(0)-&amp;gt;setG(0)-&amp;gt;setB(255);&lt;br&gt;
$image = $service-&amp;gt;update($image);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Very basic, but does the job.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Manipulating Data with PHP: performing ETL operations</title>
      <dc:creator>Eric COURTIAL</dc:creator>
      <pubDate>Tue, 07 Jul 2020 07:23:25 +0000</pubDate>
      <link>https://forem.com/ecourtial/manipulating-data-with-php-performing-etl-operations-g4j</link>
      <guid>https://forem.com/ecourtial/manipulating-data-with-php-performing-etl-operations-g4j</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Data manipulation is one of the basic and repetitive operation we perform as a developer. Sometimes we also want to process specific inputs to get a specific result.&lt;/p&gt;

&lt;p&gt;This kind of operation is called ETL - Extract, Transform, Load. In my job we have been working recently on a big migration project, and we had to use a third-party library, on a small basis at the beginning, but in the end we choosed to fork it and to make it to evolve, and used it as the core of our migration. Below is a quick tour of how this small library can help you. You can find it &lt;a href="https://github.com/wizaplace/php-etl"&gt;here&lt;/a&gt; and simply install it via composer :&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;composer require wizaplace/php-etl&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Uses cases
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Generic
&lt;/h3&gt;

&lt;p&gt;You can use this library in two main cases :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;first one, you simply want to extract data from one or various sources: CSV, JSON... in order to use them directly&lt;/li&gt;
&lt;li&gt;second one, you need to realize a complete process of data manipulation: extracting and transforming them before to use
or save them in a different format.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Our use case
&lt;/h3&gt;

&lt;p&gt;We used this library as a tool in the context of a major migration for one of our customers. We had to extract data of different formats (CSV, JSON...) from various sources (files, API...) in order to process and aggregate them before injecting them in the new application of our customer.&lt;/p&gt;

&lt;h2&gt;
  
  
  The library
&lt;/h2&gt;

&lt;p&gt;At its origin the library was developed by Leonardo Marquine. We started by using this version, but since we needed to add extra components and because it seemed that there was no more activity on the original repository, we decided to fork it and continue in our own way. We cleaned a lot of stuff, like dropping the support for PHP 5.x, added some new components, you can check our changelog &lt;a href="https://github.com/wizaplace/php-etl/blob/master/changelog.MD"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;After this extensive work, we are still maintaining it: we still have some projects for it (new classes for instances) but so far we did not plan a major refit, we currently do not consider to rewrite it since it does the job well in its current version.&lt;/p&gt;

&lt;p&gt;The utilization is quite straightforward: you need a instance of the ETL class, which orchestrates everything else (extraction and other optional operations like transformation and persistence).&lt;/p&gt;

&lt;p&gt;In this very short and simple example, I extract lines from a CSV, with filters, the iterator returning an object, one for each line of the CSV:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        $inputFile = 'assets/tuto/customers.csv';

        return $this-&amp;gt;csvEtl
            -&amp;gt;extract(
                $this-&amp;gt;csvExtractor,
                $inputFile,
                [
                    'throwError' =&amp;gt; true,
                    'delimiter' =&amp;gt; ';',
                    'columns' =&amp;gt; ['id', 'email']
                ]
            )
            -&amp;gt;toIterator();
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In this other simple example, I extract data from a CSV and transform them before saving them in another CSV.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        $inputCsvFile = 'assets/tuto/customers.csv';
        $outputCsvFile = 'assets/tuto/output.csv';

        $this-&amp;gt;etl
            -&amp;gt;extract(
                $this-&amp;gt;csvExtractor,
                $inputCsvFile,
                [
                    'throwError' =&amp;gt; true,
                    'delimiter' =&amp;gt; ';',
                    'columns' =&amp;gt; ['id', 'email']
                ]
            )
            -&amp;gt;transform($this-&amp;gt;renameColumns, ['columns' =&amp;gt; ['email' =&amp;gt; 'courriel']])
            -&amp;gt;load($this-&amp;gt;csvLoader, $outputCsvFile)
            -&amp;gt;run();
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In a few lines of code, you can perform some very specific operations, with a lot of built-in features. On top of that you can also easily integrate your own classes in the pipeline, for instance your own transformer, or even aggregate data from different sources&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;It is a basic and light library. Is still contains old way to proceed (legacy from PHP5 compatibility) but it does the job, and thanks to the work done by the authors of the original version, we did not have any issue to make it evolve and integrate new components.&lt;/p&gt;

&lt;p&gt;Obviously you cannot compare it with paying, high-end, ETL solutions, but for most of operations, it will be enough.&lt;/p&gt;

</description>
      <category>php</category>
      <category>etl</category>
    </item>
  </channel>
</rss>
