facing problem in JMagick(URGENT)

View: New views
1 Messages — Rating Filter:   Alert me  

facing problem in JMagick(URGENT)

by khan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I need assistence.
I m creating water mark using JMagick but faced problem in setting aInfo.setBorderColor(arg0) method.Its not working,Can u guide me.

i dont wan to use setStroke()


///////////////////////////////////////////////////////////////////////////
public byte[] getBigImagePreviewContentData(int contentDataId) {
    mLogger.info("private void getBigImagePreviewContentData(int contentId) { ");
    byte[] big_bytes = null;
    try {
      // Getting the ContentData object by id.
      ContentData data = null;
      data = (ContentData) new ContentDataDAO().retrieveOriginalWithDataByContentID(contentDataId).get(0);

      // get the preview image dimension.
      int BIG_PREVIEW_SIZE = (new Integer((String) Configuration.getInstance().getProperties().get("content.data.image.big.preview"))).intValue();
      String imageMarkText = (String) Configuration.getInstance().getProperties().get("content.data.image.watermark.text");
      String imageTextAlignment = (String) Configuration.getInstance().getProperties().get("content.data.image.watermark.alignment");
      imageMarkText = imageMarkText.toUpperCase();

      // read in the original content data
      byte[] bytes = data.getContentData();
      ImageInfo info = new ImageInfo();
      MagickImage image = new MagickImage(info, bytes);

     
     
      // get the image dimension
      Dimension dim = image.getDimension();
     
//      System.out.println("Blob width is " + dim.width);
//      System.out.println("Blob heght is " + dim.height);
     
      int height = BIG_PREVIEW_SIZE;
      int width = BIG_PREVIEW_SIZE;

      // get the new dimension based on the preview requirement
      if(dim.width > dim.height) {
        height = (int) height * dim.height / dim.width;
      }
      else {
        width = (int) width * dim.width / dim.height;
      }

//      System.out.println("After changing the width  " + width);
//      System.out.println("After changing the  heght is " + height);
     
      // create the big preview image
      MagickImage scaled = image.scaleImage(width, height);

      // set and write the text on the big preview image
      DrawInfo aInfo = new DrawInfo(info);
     
     aInfo.setPrimitive("Rectangle 10 10 190 90");
   
   
     
     
      aInfo.setOpacity(0);

      // aInfo.setFont("Verdana");
      aInfo.setFont("Verdana");
     
      aInfo.setPointsize(height/6);
       aInfo.setFill(PixelPacket.queryColorDatabase("white"));
       aInfo.setBorderColor(PixelPacket.queryColorDatabase("black"));
     //aInfo.setStroke(PixelPacket.queryColorDatabase("black"));
       
      aInfo.setText(imageMarkText);
     

      // set the watermark orientation
      int left = 0;
      int top = 0;
      if(imageTextAlignment.trim().equals(TEXT_ALLIGNMENT_TOP)) {
        left = (int) width / 6;
        top = (int) height * 1 / 5;
      }
      else if(imageTextAlignment.trim().equals(TEXT_ALLIGNMENT_CENTER)) {
        left = (int) width / 19;
        top = (int) height * 3 / 5;
      }
      else if(imageTextAlignment.trim().equals(TEXT_ALLIGNMENT_RIGHT)) {
        left = (int) width / 20;
        top = (int) aInfo.getPointsize();//20;
      }

      if(dim.width < dim.height) {
        left = 18;
      }

      // setting angle to -90
      if(imageTextAlignment.trim().equals(TEXT_ALLIGNMENT_RIGHT)) {
        scaled = scaled.rotateImage(-90);
      }
      //mahmood khan
//      aInfo.setGravity(GravityType.NorthEastGravity);
      aInfo.setGeometry("+" + left + "+" + top);
      scaled.annotateImage(aInfo);
      scaled.setFileName("");
     

      // setting angle to 90
      if(imageTextAlignment.trim().equals(TEXT_ALLIGNMENT_RIGHT)) {
        scaled = scaled.rotateImage(90);
      }

      // get the binary preview image.
      big_bytes = scaled.imageToBlob(info);
    }
    catch(Exception e) {
            mLogger.error("Exception caught when getting and storing preview: " + e);
    }
    return big_bytes;
  }
/////////////////////////////////////////////////////////////////////////////////////////////


Thanks,
Mahmood khan