How can I get the size of the image from an ImageDraw.Draw object? - python-imaging-library

I have a Pillow (PIL) image called img. I create a drawing object with drawer = ImageDraw.Draw(img). Now I pass drawer to a function. How can that function see the size of the image? (If I just pass the image, I can get the size easily with img.size)

TL;DR drawer.im.size
The ImageDraw.Draw object has a property called im that can be used to get a ImagingCore object (Note that this is not the usual Image object) which has a size property. Testing it, the size property seems to match that of the original image, so that is what I will use for now.

Related

How to manipulate size and position of image inside a digital signature rectangle? Itextsharp

I need to simultaneously stamp both a string (details of the user) and an image containing an actual signature in a pdfDocument. The string and image are successfully stamped on the document, however, the image of the actual signature is being stretched to fit the rectangle of the whole signature. how do i fix this and manipulate the size and position of the image?
I used both Layer2Text and Image function in one stamper declaration. Can anyone help me?
Thanks in advance
Instead of merely setting the Layer2Text and Image and letting iTextSharp arrange everything, you can create the signature appearance all by yourself on the PdfTemplate returned by GetLayer(2).
If you need some inspiration on how to fill that layer, you can look at the PdfSignatureAppearance.cs method GetAppearance(), more exactly the section between
if (app[2] == null) {
and
}
if (app[3] == null && !acro6Layers) {
This is where iTextSharp creates the default appearance on the PdfTemplate t. Your code may vary only slightly.

load UIImage low quality

I would like to know how to load first a low quality UIImage and then load the original UIImage in high quality. Does it have an algorithm to do this in objective-c? I checked it out the class NYXImagesKit but it only works with iOS 5+ because it uses Core Image framework...And i need to work this with iOS 4.3+. Its effect is like Facebook app does.
JUST A edit:
check this out :
http://www.codinghorror.com/blog/2005/12/progressive-image-rendering.html
i want to do the Effect number 2
From the docs:
Incrementally Loading an Image
If you have a very large image, or are loading image data over the web, you may want to create an incremental image source so that you can draw the image data as you accumulate it. You need to perform the following tasks to load an image incrementally from a CFData object:
Create the CFData object for accumulating the image data.
Create an incremental image source by calling the function CGImageSourceCreateIncremental.
Add image data to the CFData object.
Call the function CGImageSourceUpdateData, passing the CFData object and a Boolean value (bool data type) that specifies whether the data parameter contains the entire image, or just partial image data. In any case, the data parameter must contain all the image file data accumulated up to that point.
If you have accumulated enough image data, create an image by calling CGImageSourceCreateImageAtIndex, draw the partial image, and then release it.
Check to see if you have all the data for an image by calling the function CGImageSourceGetStatusAtIndex. If the image is complete, this function returns kCGImageStatusComplete. If the image is not complete, repeat steps 3 and 4 until it is.
Release the incremental image source.
You can refer below link, it may be help you
uiimage-dsp

I have one pixel length color image and i wanted to scale up it according to new length value.

So color image length will change dynamically. I will use it on the custom graph. What is the best solution for this? now i am using Resize category by extending UIImage.
Thanks advance..
For this task you could use instance method of UIImage stretchableImageWithLeftCapWidth:topCapHeight:. Suppose
[imgObj stretchableImageWithLeftCapWidth:4.0f topCapHeight:5.0f];
This method call will live 4 pix from left & right and 5 pix from top & bottom of your image and will repeat the rest image in middle.
But in your case both values will be Zero.

Iphonesdk boundries checking for coloring

im creating and app where user already have an image (with different objects) without colors, i have to check the object and then color with respected color with the touch on that objects. how should i do this. can anyone help me.
I would say that that is non-trivial. I can only give hints since I have not done such an app yet.
First, you need to convert the image into a CGImageRef, for example by doing [uiimage_object CGImage].
Next you need convert the CGImageRef into array of pixel colors. You can follow the tutorial at http://www.fiveminutes.eu/iphone-image-processing/ for sample code. But for your app you need to convert the array into two dimension based on image width and height.
Then, use the coordinate of the user touch to access the exact pixel color value from the array. Next you read off the color values of the surrounding pixels and determine if color is similar to the touched pixel or not (you might need to read some wikipedia articles etc on doing the color comparison). If the color is similar, change the color to the one you want. Recurse until the surrounding color is different (i.e. you hit the boundary).
When you are finished modifying the pixel color value array, you need to convert the array back into CGImageRef using CGImageCreate function. Then you convert back to UIImage using [UIImage imageWithCGImage:imageref].
Now you are on your own to implement the steps into code. It would be unreasonable if you expect me to code all that for you, wouldn't it?

why do getOffsetWidth() and getElement().getClientWidth() return 0 for a Widget in GWT?

I'm using RaphaelGWT to draw shapes with the underlying RaphaelJS library. Both projects are wonderful. However I was stuck for awhile on the issue of Text objects in Raphael being displayed as centered by default.
I've tried to create one Text object and let it be centered by default, then measure its width in order to adjust the position for a 2nd text object and then remove the first. But I can't get the width of the original Text object.
FYI, in RaphaelGWT, the Shape objects used extend Widget. So I've tried getAbsoluteLeft(), getElement().getAbsoluteRight(), getOffsetWidth(), getElement().getClientWidth(). getAbsoluteLeft() is the only one that returns what I would expect. getAbsoluteRight()returns the same value as getAbsoluteLeft(), and both getOffsetWidth() and getElement().getClientWidth() return 0.
Why?
FYI, I calculated the width from the original x value used to create the Text Shape (x then became the center) and getAbsoluteLeft(), which actually returned the expected value.
The element has to be visible for getOffsetWidth() to return correct values.