PHP code example of pixelfactory / psd-php

1. Go to this page and download the library: Download pixelfactory/psd-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pixelfactory / psd-php example snippets




$psd = new \Psd\Psd('./image.psd');

$psd = new \Psd\Psd('./image.psd');
$psdSimpleMethods = $psd->getShortcuts();

echo $psdSimpleMethods->getWidth();    // Print file width
echo $psdSimpleMethods->getHeight();   // Print file height

$psd = new \Psd\Psd('./image.psd');
$psdSimpleMethods = $psd->getShortcuts();

var_dump($psdSimpleMethods->savePreview('./out.png')); // Print 'true' if file be saved

// TODO

// TODO

// TODO

// TODO

echo $psd->getHeader()->getMode();     // Return file mode (int)
echo $psd->getHeader()->modeName();    // Return file mode name
echo $psd->getHeader()->getChannels(); // Return file count channels

/** @var \Psd\FileStructure\Resources\Resource\Guides\GuidesData[] $guides */
$guides = $psd
    ->getResources()
    ->getResourceById(\Psd\FileStructure\Resources\Resource\ResourceBase::RESOURCE_ID_GUIDES)
    ->getData();

foreach ($guides as $guide) {
    printf("%s - %s\n", $guide->getDirection(), $guide->getLocation()); // Result: 'vertical - 100'
}

// TODO

/* @var Psd\Image\ImageExport\Exports\Png $exporter */
$exporter = $psd->getImage()->getExporter(\Psd\Image\ImageExport\ImageExport::EXPORT_FORMAT_PNG);

/** @var Imagick $image */
$image = $exporter->export();
/** @var bool $status */ 
$status = $exporter->save('./out.png');

composer