Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
Mr Marsh  
#1 Posted : Thursday, June 21, 2007 7:43:12 PM(UTC)
Mr Marsh

Rank: Member

Groups: Member
Joined: 5/2/2007(UTC)
Posts: 5

Hi, I cannot seem to find any reference to replacing an image on a layer that is in a PSD file. I want users to be able to select an image (that they have previously uploaded) and type a caption into a text box and then merge the image and text using the PSD Add-in to create the resultant jpg. I'd have a template PSD file which would contain a blank layer for the image and a text placeholder.

Is this possible and does anyone have any examples?

thanks in advance

Peter
Dmitry  
#2 Posted : Tuesday, June 26, 2007 12:05:10 PM(UTC)
Dmitry

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 8/3/2003(UTC)
Posts: 1,070

Thanks: 1 times
Was thanked: 12 time(s) in 12 post(s)
Hello,

We will post sample in a few days.
Sincerely yours,
Dmitry Sevostyanov

UserPostedImage Follow Aurigma on Twitter!
Tanya  
#3 Posted : Tuesday, June 26, 2007 4:48:12 PM(UTC)
Tanya

Rank: Advanced Member

Groups: Member
Joined: 5/14/2007(UTC)
Posts: 24

Was thanked: 1 time(s) in 1 post(s)
Hello,

Here is the code sample.

It uses Template.psd as a template to create new jpg file which contains hardcoded image and text.

Code:


        private void NewProcessPsd()

        {

            string newText = "Some text text text";

            Aurigma.GraphicsMill.Bitmap newImage = new Aurigma.GraphicsMill.Bitmap(@"C:\temp\IMG_2516.jpg");
            Aurigma.GraphicsMill.Codecs.AdvancedPsdReader psdReader = new Aurigma.GraphicsMill.Codecs.AdvancedPsdReader(@"C:\temp\template.psd");

 

            //Determining PSD pixel format

            Aurigma.GraphicsMill.Codecs.AdvancedPsdFrame frame0 = (Aurigma.GraphicsMill.Codecs.AdvancedPsdFrame)psdReader.LoadFrame(0);

            Aurigma.GraphicsMill.PixelFormat psdPixelFormat = frame0.PixelFormat;

 

            //Creating result bitmap

            Aurigma.GraphicsMill.Bitmap resultImage = new Aurigma.GraphicsMill.Bitmap(psdReader.Width, psdReader.Height, psdPixelFormat);

            resultImage.HorizontalResolution = frame0.HorizontalResolution;

            resultImage.VerticalResolution = frame0.VerticalResolution;

 

            //draw background image

            Aurigma.GraphicsMill.Codecs.AdvancedPsdFrame backgroundFrame = (Aurigma.GraphicsMill.Codecs.AdvancedPsdFrame)psdReader.LoadFrame(1);

            if (backgroundFrame.Type == Aurigma.GraphicsMill.Codecs.PsdFrameType.Raster)

            {

                Aurigma.GraphicsMill.Bitmap rasterLayer = new Aurigma.GraphicsMill.Bitmap();

                backgroundFrame.GetBitmap(rasterLayer);

                DrawLayerOnImage(resultImage, rasterLayer, backgroundFrame.Left, backgroundFrame.Top, 1.0f);

            }

            else

            {

                MessageBox.Show("The first layer should be a background");

                return;

            }

 

            //draw text

            Aurigma.GraphicsMill.Codecs.AdvancedPsdTextFrame textFrame = (Aurigma.GraphicsMill.Codecs.AdvancedPsdTextFrame)psdReader.LoadFrame(2);

            if (textFrame.Type == Aurigma.GraphicsMill.Codecs.PsdFrameType.Text)

            {

                Aurigma.GraphicsMill.Drawing.GdiGraphics graphics = resultImage.GetGdiGraphics();

 

                int textY = (int)textFrame.TextBox.Top;

                int textX = (int)textFrame.TextBox.Left;

                int textWidth = (int)textFrame.TextBox.Width;

                int textHeight = (int)textFrame.TextBox.Height;

 

                Aurigma.GraphicsMill.RgbColor rgbColor = (Aurigma.GraphicsMill.RgbColor)textFrame.Color.ConvertColorSpace(Aurigma.GraphicsMill.ColorSpace.Rgb);

                Aurigma.GraphicsMill.Drawing.SolidBrush brush = new Aurigma.GraphicsMill.Drawing.SolidBrush(rgbColor);

 

                System.Drawing.RectangleF blackBox = textFrame.Font.GetBlackBox(textFrame.Text);

 

                textY = textY + (int)blackBox.Y;

                textHeight = textHeight + (int)textFrame.Font.Size - (int)blackBox.Height;

 

                graphics.DrawString(newText, textFrame.Font, brush, new System.Drawing.RectangleF(textX, textY, textWidth, textHeight), Aurigma.GraphicsMill.Drawing.TextTrimmingMode.EndEllipsis, false, false, false);

            }

            else

            {

                MessageBox.Show("The second layer should be a text");

                return;

            }

 

            //draw image

            Aurigma.GraphicsMill.Codecs.AdvancedPsdFrame imageFrame = (Aurigma.GraphicsMill.Codecs.AdvancedPsdFrame)psdReader.LoadFrame(3);

            if (imageFrame.Type == Aurigma.GraphicsMill.Codecs.PsdFrameType.Raster)

            {

                newImage.Transforms.Resize(imageFrame.Width, imageFrame.Height, Aurigma.GraphicsMill.Transforms.InterpolationMode.HighQuality);

                DrawLayerOnImage(resultImage, newImage, imageFrame.Left, imageFrame.Top, 1.0f);

            }

            else

            {

                MessageBox.Show("The third layer should be an image");

                return;

            }

 

            //Save result jpg

            resultImage.Save(@"C:\temp\test.jpg");

        }

       

        

        private void DrawLayerOnImage(Aurigma.GraphicsMill.Bitmap image, Aurigma.GraphicsMill.Bitmap layer, int layerLeft, int layerTop, float layerOpacity)

        {

             if (image.IsEmpty || layer.IsEmpty)

                  throw new ApplicationException("Cannot draw layer. Image and layer bitmap cannot be empty.");

 

             if (image.IsCmyk && layer.IsRgb)

                  layer.ColorManagement.ConvertToContinuous(Aurigma.GraphicsMill.ColorSpace.Cmyk, true, false);

                        

             layer.Draw(image, layerLeft, layerTop, layer.Width, layer.Height, Aurigma.GraphicsMill.Transforms.CombineMode.Alpha, layerOpacity, Aurigma.GraphicsMill.Transforms.InterpolationMode.HighSpeed);

             layer.Dispose();

        }




Find template.psd in attachement.

Best regards,
Tatyana Bertyakova

Edited by user Tuesday, December 18, 2007 3:09:53 AM(UTC)  | Reason: Not specified

File Attachment(s):
Template.zip (586kb) downloaded 84 time(s).
Best regards,
Tatyana Bertyakova

UserPostedImage Follow Aurigma on Twitter!
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.