4

I was trying to read a psd file from database as like pdf or images but I failed. Is there any way to read or display psd file in browser?

Arman H
  • 1,594
  • 18
  • 22

2 Answers2

5

You can use ImageMagick for this,

$im = new Imagick("image.psd");

foreach($im as $layer) {
  // do something with each $layer

  // example: save all layers to separate PNG files
  $layer->writeImage("layer" . ++$i . ".png");
}

Refer to this question too: PHP: Get the position (x, y) of the layer of PSD file

OR You could use something like this: PSD Library - Read .psd files without any 3rd party libraries.

NID
  • 3,238
  • 1
  • 17
  • 28
  • thanks @Bilal . i know this process. It is just converter psd to png. i said i want to display accurate psd file in my output. – Arman H Jun 13 '17 at 09:26
  • A PSD file is a file format used by and specific for Adobe Photoshop. Other applications (like your webbrowser) do not know how to read it. You need to convert it to another format. – NID Jun 13 '17 at 09:27
  • yes bro . thanks for your suggest. can i make a download link of this psd file from database? @Bilal – Arman H Jun 13 '17 at 09:30
  • do you want the user to download the image directly from the db itself? – NID Jun 13 '17 at 09:33
  • yes user can be download but not image psd file.that mean i want to make a link for psd file to download it. – Arman H Jun 13 '17 at 11:34
  • Refer to this SO questions: https://stackoverflow.com/questions/32329586/how-do-i-download-a-file-using-php-and-mysql-db https://stackoverflow.com/questions/7793009/how-to-retrieve-images-from-mysql-database-and-display-in-an-html-tag – NID Jun 13 '17 at 11:38
1

You can use the code below. It uses a webapi but it's free and has no limitations.

<?php
$url = 'http://server.com/image.psd';
$data = json_decode(file_get_contents('http://api.rest7.com/v1/image_convert.php?url=' . $url . '&format=png'));

if (@$data->success !== 1)
{
    die('Failed');
}
$image = file_get_contents($data->file);
file_put_contents('rendered_page.png', $image);

Additional bonus- it reads not only PSD images but many, many more.

You can get more examples here: http://rest7.com/image_convert

I am not affiliated with this website but I use it for over a week now so if you have questions I can try to answer :)

Jack
  • 173
  • 1
  • 3