This forum contains outdated content and is available for reading only. Please contact technical support if you have any questions.

PsDProcessor.Render change the position

Hello,

like the subject explain it, when I Render a PSD template, the position of elements in result (in jpg) are a little bit different than the original.
I join my code and also original and render.

Do you have any idea why ?

Original
attach #1392

Render
attach #1391


            //Create a font fetcher and specify a local folder to download fonts to.
            var fontResolver = new FontResolver(@"Fonts");

            //Set font source for the fetcher.
            //Add a local font source.
            fontResolver.AddSource(new FileSystemSource(@"C:\tmp\PSD\Fonts"));

            var psdProcessorFont = new PsdProcessor(fontResolver);

            var missingFonts = psdProcessorFont.GetMissingFonts(file);

            if (missingFonts.Count() > 0)
            {
                Console.WriteLine("The following fonts are not found in the given font sources: ");

                foreach (var font in missingFonts)
                    Console.WriteLine("  {0}", font);
            }
            else
            {
            }



            var psdProcessor = new PsdProcessor(fontResolver);

             psdProcessor.TextCallback = (processor, textFrame, textstring) =>
            {
                var text = processor.ProcessText(textFrame);
                try
                {
                    if (textFrame.Name == "CustomerName")
                    {
                        text.String = "<p><span>Cher David,</span></p>";
                    }

                    return text;
                }
                catch
                {
                    return text;
                }
            };
            psdProcessor.Render(file, file.Replace(".psd",".jpg"));
Hi David,

GM rendering result will always be a little bit different because we have different rendering engines. Sometimes we are pretty close to original, sometimes not. It also depends on features used for text formatting. Sometimes we have different math maybe, sometimes, we don't have the support of all necessary features.

It's hard to say for sure regarding your image without seeing the original PSD. I see different image dimensions of the source and produced images, and it seems to me strange.

Photoshop stores a rendered copy of each frame along with meta information. So you can change the text of frames with a placeholder, and keep all other frames untouched.

Try to add a FrameCallback handler to your code:

psdProcessor.FrameCallback = (procesor, frame) =>
{
    if (frame.Name == "CustomerName")
        return procesor.ProcessFrame(frame);

    var gc = new GraphicsContainer(frame);
    using (var gr = gc.GetGraphics())
    {
        // Frame raster data comes directly from PSD.
        gr.DrawImage(frame, frame.X, frame.Y);
    }

    return gc;
};
Eugene Kosmin;32665
Hi David,

GM rendering result will always be a little bit different because we have different rendering engines. Sometimes we are pretty close to original, sometimes not. It also depends on features used for text formatting. Sometimes we have different math maybe, sometimes, we don't have the support of all necessary features.

It's hard to say for sure regarding your image without seeing the original PSD. I see different image dimensions of the source and produced images, and it seems to me strange.

Photoshop stores a rendered copy of each frame along with meta information. So you can change the text of frames with a placeholder, and keep all other frames untouched.

Try to add a FrameCallback handler to your code:

psdProcessor.FrameCallback = (procesor, frame) =>
{
    if (frame.Name == "CustomerName")
        return procesor.ProcessFrame(frame);

    var gc = new GraphicsContainer(frame);
    using (var gr = gc.GetGraphics())
    {
        // Frame raster data comes directly from PSD.
        gr.DrawImage(frame, frame.X, frame.Y);
    }

    return gc;
};


Hello Eugene,

Thank you for your feed back. I have try your code but it doesn't work on my computer.

var gc = new GraphicsContainer(frame);

GraphicsContainer is not recognized and I had the "using Aurigma.GrpahicsMill"

Do you have any idea ?

Thank you
That's OK. PsdProcessor uses GraphicsMill under the hood, so in some cases, you need to add the appropriate using statement.
Do you experience any problems after adding using Aurigma.GraphicsMill?
Eugene Kosmin;32675
That's OK. PsdProcessor uses GraphicsMill under the hood, so in some cases, you need to add the appropriate using statement.
Do you experience any problems after adding using Aurigma.GraphicsMill?


using Aurigma.GraphicsMill was already there but it's "grey"

Just found it, it's using Aurigma.GraphicsMill.AdvancedDrawing that had to be added 🙂