Writing text to Image in Google App Engine (Java) - java

I'm writing code that runs on Google App Engine (Java). What I'm trying to do is augment an existing image by adding text. GAE does not have any text handling in its ImagesService.
Does anyone have any idea?
I'd like my code to look something like this:
...
// Read image
byte[] pageData = readImage("images/page.png");
Image pageImage = ImagesServiceFactory.makeImage(pageData);
// Add text here
...
return pageImage;

If you just need to overlay some simple text you could combine the Google Charts API with the Composite image function in the AppEngine Image API to get the desired result.
First construct a URL and use urlfetch from your app to grab the required text-image via the Charts API like:
URL: http://chart.apis.google.com/chart?chs=300x50&cht=p3&chtt=hello&chts=FFFFFF,24&chf=bg,s,000000
(Note the size, and colour params in this url)
Open your image with the Image API and use Composite with the image you wish to overlay text on.

You can extend the colors on Google charts with alpha values, that way you can have a transparent png that you can overlay on top of another image using the Composite function.
http://chart.apis.google.com/chart?chs=300x50&cht=p3&chtt=hello&chts=000000FF,24&chf=bg,s,00000000

Related

How to know that provided URL is Image or Video in Android Studio

I am Using Firebase as Database where user can Upload Image or Video so I am Fetching URL from my database so I am getting two URLs one of them can be either video or image so what can I do to detect the URL.
Let Suppose this is the URL.
This is the example URL. NOTE URL can be different
any help will be appreciated
Edited
for better understanding I will providing some example code:
MyUserModel model; //this is the model class where I can get the url in String
String Url = model.getUrl(); //its URL can be video or image
//Can I write something like this:
//does any method like this : isVideo();
// if the url is video then this function will return true else false;
if(isVideo(Url)){
videoView.setVideoPath(Url); //and other stuffs
}else{
Glide.with(context).load(Url).into(ImagView); //something like this.
}
...
NOTE : SOME URLS DON'T HAVE EXTENTIONS LIKE PNG, MP4, JPG ETC. I am saying this because I have a some URLs with no extension related to mp4 or png etc.
I will suggest you to have one column named as "type" and keep 0 for image and 1 for video when you are saving image/video into data base. This way you can recognise the type easily.
You may need to tweak UI little bit. You can provide an option to capture image from UI and launch camera app only to capture image. Similarly provide an option to capture only video. This way you can make sure at front end user is capturing either image or video at a time. Save that type value in firebase db as above.

Vaadin file preview

Can anyone support me with the following issue:
I am working with Vaadin and need to develop a code tt will allow the user to preview the file in such formats as pdf, image, video and audio files. All files are stored in database and may be or various possible types. For pdf it is enough to add the following code:
StreamResource resource = file.downloadFileFromDatabase();
Embedded pdf = new Embedded("", resource);
pdf.setMimeType("application/pdf");
pdf.setType(Embedded.TYPE_BROWSER);
pdf.setSizeFull();
pdf.setHeight("310px");
verticalLayout.setSizeFull();
verticalLayout.addComponent(pdf);
verticalLayout.setExpandRatio(pdf, 1.0f);
But this code doesn't work with video and audio files. Do I need to add a sort of if-else statement to arrange preview of file in accordance with its format? Thank u in advance.
Playing videos from vaadin is possible, there exists the Video class for this.
But since it renders a html5 <video> tag, it requires url as video source. In addition to this, you need a browser supporting the video tag, and the specific video encodings your videos have.
This can help for the player elements to control playback:
https://vaadin.com/directory#!addon/mediaelementjs-player
Here some more info for debugging your potential problem:
https://vaadin.com/forum#!/thread/2445276

ZXing library can't decode Datamatrix barcode

I'm trying to use ZXing library to decode Datamatrix barcode. Here are my code sample:
BufferedImage bi = img.getBufferedImage();
Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
LuminanceSource source = new BufferedImageLuminanceSource(bi);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
DataMatrixReader dataMatrixReader = new DataMatrixReader();
try {
Result res = dataMatrixReader.decode(bitmap,hints);
System.out.println("resultText = "+res.getText());
} catch (Exception e) {
System.out.println("failed to get resultText");
e.printStackTrace();
}
I've seen almost the same samples many times accross https://stackoverflow.com/ and other sites, but this approach does not working for me in this form.
As a source I'm using images grabbed from IR-camera. Here are example image:
As you see, the barcode is almost exactly at the center of an image, as Sean Owen recommended here and here. If I programmatically convert this image to black&white and crop image to bound barcode with some white space around it only, then ZXing works perfectly with images like this. But the problem is that barcode in real could have little deformations, so my simple algorythm can't help me to crop image properly. More over barcode could be placed not exactly in the center of an image and cold have a little bit different brightness. I saw threads mentioning OpenCV capabilities to find out placement of speciects objects on the image, like this one, but they are quite old. Is something changed since then? And what should i yet certainly consider to write 100% reliable datamatrix decoder (and detector) in my specific situation?
I decided to supply LuminanceSource and BinaryBitmap images made of .toString() text output of correcponding objects for reference:
http://s28.postimg.org/l53sykhx9/Binary_Bitmap.png
and /65z0vlbpl/Luminance_Source.png (at the same domain). They are looking good and ready for decoding, but what is wrong with decoding then.
After all this image and similar ones recognized and decoded very well with smartphone software and i'm just wanted achieve same results.
you need to enable it from settings programmatically or manually.
in class DecodeThread.java you can see the line that enables data matrix encoding
decodeFormats.addAll(DecodeFormatManager.DATA_MATRIX_FORMATS);

GraphicsMagick + im4java, how can I remove color profile (and other redundant data)

I'm using graphicsmagick + im4java for generating thumbnails in my web application. Unfortunately as I can see, while processing pictures taken with photo cameras, the thumbnails contains all original data such color profile, aperture, camera's manufacturer/model etc. In other words much more things than required for displaying just simple thumbnail on the page. Of course it causes large thumbnail's file size. The thumbnail for the same photo which was saved for the web from any graphic editor is much smaller.
How can I get rid of unwanted data with im4java before further processing?
Problem solved, following this GM gist:
mogrify +profile '*' -define jpeg:preserve-settings
I managed the problem in im4java with p_profile(java.lang.String profileName) method:
ConvertCmd cmd = new ConvertCmd();
IMOperation op = new IMOperation();
op.addImage(sourcePath);
op.p_profile("*");
op.scale(123);
op.addImage(targetPath);
cmd.run(op);

How to get thumbnail from Dropboxapi using JAVA SDK?

I am working with Dropbox API using JAVA SDK. I try to get the thumbnail for each image in my dropbox account via API. Honestly, after I read the class and they just provided the description which is not useful enough for the beginner. I begin my code like this
public void getThumbnails() throws DropboxException{
DropboxInputStream dis = api.getThumbnailStream("/Koala.jpg", ThumbSize.ICON_256x256, ThumbFormat.JPEG);
}
What I don't understand is:
I should return something to client side in order to show the thumbnail I got from DropboxAPI but I don't know what I should return. Maybe DropboxInputStream?
How do I get the thumbnail from API? I try to find the example or guide for a day but I can't find any guide...
please someone guide me how to get the thumbnail via dropbox API
DropboxInputStream is just a FilterInputStream so after you get the input stream like you wrote you can just iterate the input stream and read it.
Then it's only a question of the way you need to present it.
Is it a Swing application you are writing? how do you need to show that image?
You should be able to read the Image with ImageIO.read
Image image = ImageIO.read(dis);
http://docs.oracle.com/javase/6/docs/api/javax/imageio/ImageIO.html

Categories

Resources