Data visualization with SAS programming

Cropping image using SAS code ??

Reply
Contributor
Posts: 56

Cropping image using SAS code ??

Hi

I have some images and I want to to crop those images so that I can use them to place on the same page . Reason to crop the image is to maintain the quality of the desired image so that I do not loose valuable space on the page while placing them on same page in PDF file .

Original image is produced by PROC GKPI in HTML file then using PROC GSLIDE it is saved as png image then using PROC GREPLAY images are placed on the same page of the pdf .

I had to to follow above complex steps to combine four graphs produced by PROC GKPI as It seems that PROC GKPI does not produce images in catalog..

Has anyone solution or alternate way of doing the task ???

SAS Employee
Posts: 967

Re: Cropping image using SAS code ??

Let me re-state your question, just to make sure I understand what you're wanting...

You want a programmatical way (in SAS) to get rid of the white-space around the Proc Gkpi gauges/etc output images, so that you can then annotate/greplay them tightly onto the same page without overlapping?

Or, if someone has an alternate way to create such a Gkpi dashboard, you'd also be receptive to that.

Contributor
Posts: 56

Re: Cropping image using SAS code ??

Yes . Exactly .

SAS Employee
Posts: 967

Re: Cropping image using SAS code ??

With the absence of any answers/suggestions, I think this might not be do-able.

This might be a good thing to contact tech support about, and ask them to enter a request for adding functionality to Proc GKPI to allow the user to better control the white-space around them.

Contributor
Posts: 56

Re: Cropping image using SAS code ??

Yeh .. This may be good idea for future version of SAS but as a soulution I also do not see any better way out of it . Anyway I never knew that we can request SAS Support for improvements in existing PROCs (don't know whether it counts or not); but yes PROC GKPI despite being execellent procedure has little to offer me regarding control on graphs. Smiley Happy

N/A
Posts: 1

Re: Cropping image using SAS code ??

i am looking forward to the solution of image cropping c# idea, i found it is hard to get rid of the white space. the quality of images is important .

SAS Employee
Posts: 967

Re: Cropping image using SAS code ??

OK - I might have figured out a programmatical (in SAS) work-around for you ...

Rather than annotating the gkpi image into a gslide within the xsys/ysys=3 0-100 coordinates, you can actually annotate the image *outside* of the visible 0-100 coordinates, thereby chopping (cropping) off the edges. ... Or, as I like to call it, literally "thinking outside the box" Smiley Happy

Here is an example where I chop off some of the left & right edges of a gkpi png, to get rid of some of the white space:

data anno_img;
length function $8;
xsys='3'; ysys='3';
x=-15; y=0; function='move'; output;
x=115; y=100; function='image'; imgpath='gkpi4.png'; style='fit'; output;
run;

goptions xpixels=300 ypixels=300;
proc gslide anno=anno_img;
run;

I'm attaching the gkpi4.png image (that I used in the example code), if you want to use that to experiment with:

gkpi4.png

SAS Super FREQ
Posts: 1,081

Re: Cropping image using SAS code ??

What sort of KPI are you using?

WDZ
N/A
Posts: 1

Re: Cropping image using SAS code ??

I've been messing around with this, since I have a similar problem with the white spaces...

What solved it for me was just setting the "correct" goptions.

The line that worked for me came from this presentation: http://www.sas.com/offices/NA/canada/downloads/presentations/TASS09/PROC-GKPI.pdf.

It was: goptions reset=all rotate=landscape device=javaimg xpixels=240 ypixels=200;

This created a compact image without all the white space in my html file. If you change the pixels, it sometimes messes it up again (e.g. xpixels=480 ypixels=400 didn't work for me, but xpixels=320 ypixels=240 did work). I'm assuming the landscape view also has to do with this (i.e. I think SAS autofits the image in some strange way and you need to trick it into doing it in a nicer way).

Hope this helps!Smiley Happy

New Contributor
Posts: 2

Re: Cropping image using SAS code ??

never try to crop image with this kind of code before. i hope i can get the best size image. image cropping is useful but can i resize image with this code.

Occasional Contributor
Posts: 9

Re: Cropping image using SAS code ??

Hi, gfimage.

Thanks for your nice sharing. Here are some code about the related image resizing process:

Imports System.Drawing

Imports System.Drawing.Imaging

Imports PQScan.PDFToImage

Namespace SpecifyImageSize

  Class Program

   Private Shared Sub Main(args As String())

   ' Create an instance of PQScan.PDFToImage.PDFDocument object.

   Dim pdfDoc As New PDFDocument()

   ' Load PDF document.

  pdfDoc.LoadPDF("sample.pdf")

   ' Set dpi to render image

  pdfDoc.DPI = 96

   'Get total page count.

   Dim count As Integer = pdfDoc.PageCount

   For i As Integer = 0 To count - 1

   'Convert page to image in target size

   Dim bmp As Bitmap = pdfDoc.ToImage(i, 100, 200)

   'Save image

  bmp.Save("output" & i & ".jpg", ImageFormat.Jpeg)

   Next

   End Sub

  End Class

But I wonder how can I accomplish the image resizing process. Do I need another image resizing SDK to help customize the size of images? I am almost a green hand here. Any suggestion will be appreciated. Thanks in advance.   

Best regards,

Arron

Ask a Question
Discussion stats
  • 10 replies
  • 981 views
  • 0 likes
  • 7 in conversation