Recent

Author Topic: [SOLVED] Converting psd files to png  (Read 538 times)

SaraT

  • Full Member
  • ***
  • Posts: 134
  • A little student
[SOLVED] Converting psd files to png
« on: April 19, 2025, 08:25:17 am »
Hi coders,

There is a unit called FPReadPSD, but there is not enough information
about reading .psd files :/

Does anybody have a working example to read .psd files and convert to .png?
I would be so thankful if somebody provide me a code to make this works.

Please and thanks.
« Last Edit: April 19, 2025, 04:28:11 pm by SaraT »

TRon

  • Hero Member
  • *****
  • Posts: 4371
Re: Converting psd files to png
« Reply #1 on: April 19, 2025, 09:14:11 am »
unit FPReadPSD reference.

wiki snippet converting from one raster format to another using fp(memory)image.

Are you able to manage that ?
Today is tomorrow's yesterday.

SaraT

  • Full Member
  • ***
  • Posts: 134
  • A little student
Re: Converting psd files to png
« Reply #2 on: April 19, 2025, 09:27:42 am »
Are you able to manage that ?

Sorry, TRon, but Im not able... this is the first time I see the FPReadPSD unit and have not worked
converting this type of file. Maybe someone else could share a working code.

Hope this unit can save with transparent png too.

Thanks for your answer.

TRon

  • Hero Member
  • *****
  • Posts: 4371
Re: Converting psd files to png
« Reply #3 on: April 19, 2025, 09:40:03 am »
No problem SaraT here we go:
Code: Pascal  [Select][+][-]
  1. program test;
  2.  
  3. {$mode objfpc}{$h+}
  4.  
  5. {
  6.   references:
  7.   - thread "Converting psd files to png"
  8.     https://forum.lazarus.freepascal.org/index.php/topic,70870.0.html
  9.  
  10.   - sample psd files
  11.     https://customerscanvas.com/help/designers-manual/adobe/photoshop/gallery.html
  12.  
  13.   - fcl-image wiki snippet
  14.     https://wiki.freepascal.org/fcl-image#Converting_between_two_raster_image_formats
  15.  
  16.   - readpsd unit reference
  17.     https://www.freepascal.org/daily/packages/fcl-image/fpreadpsd/index-4.html
  18. }
  19.  
  20. uses
  21.   sysutils, fpImage, fpreadpsd, fpwritepng;
  22.  
  23. procedure processFile(Filename: string);
  24. var
  25.   image  : TFPCustomImage;
  26.   reader : TFPCustomImageReader;
  27.   writer : TFPCustomImageWriter;
  28. begin
  29.   Image  := TFPMemoryImage.Create(10, 10);
  30.   Reader := TFPReaderPSD.Create;
  31.   Writer := TFPWriterPNG.Create;
  32.   Image.LoadFromFile(FileName, Reader);
  33.   Filename := ChangeFileExt(Filename, '.png');
  34.   Image.SaveToFile(Filename, Writer);
  35. end;
  36.  
  37. var
  38.   Filename : string = 'placeholders-with-frames.psd';
  39. begin
  40.   if FileExists(Filename)
  41.     then ProcessFile(Filename)
  42. end.
  43.  

I have no idea about transparency. PSD is not really something I use on a regular base.
Today is tomorrow's yesterday.

SaraT

  • Full Member
  • ***
  • Posts: 134
  • A little student
Re: Converting psd files to png
« Reply #4 on: April 19, 2025, 04:29:13 pm »
No problem SaraT here we go:

Thanks a lot, TRon.

TRon

  • Hero Member
  • *****
  • Posts: 4371
Re: [SOLVED] Converting psd files to png
« Reply #5 on: April 19, 2025, 06:58:36 pm »
You're welcome SaraT.

Note that the example code did not free the created instances of reader, writer and image (FUAI).

You'd need to correct that when using the example in production code.
Today is tomorrow's yesterday.

 

TinyPortal © 2005-2018