Use Alibaba cloud's OSS Image Processing to create thumbnail images - alibaba-cloud

I am using Alibaba-cloud. Using its Object Storage Service Image processing, I need to generate square thumbnails of images. But those thumbnails must be resized in a way that it fits the square perfectly. They shouldn't lose its aspect ratio and the extra portions must get cropped. The thumbnails should look just like the thumbnail images that are shown in any gallery app on phones. How should I achieve this?

OSS provides a way to scale an image up or down using Resize operation. You can create a smaller cropped version of your images using the fixed width and height method. This method handles automatic cropping, hence your aspect ratio will persist. To do this, there are a few parameters that you must know:
m - scaling mode (fixed/fill/pad/mfit/lfit)
w - width
h - height
To create your thumbnails,
you must set scaling mode to fill. Fill mode retains a cropped and a centered minimum image extending out of the rectangle of the specified width and height. m_fill
And lastly, you must set the w and h parameters; for your use case, it will help them to be equal. h_100, w_100
So this is what your URL will end with: x-oss-process=image/resize,m_fill,h_100,w_100
So you can resize any image to an image like this.

Alibaba Cloud OSS Image Processing (IMG) is an image processing service provides API to process the images effectively.
You can simply request a thumbnail of the images by creating a style.
Style:
Image Service allows you to save image processing operations and parameters as an alias, that is, a style. With styles, a series of operations can be achieved through a very short URL.
Channel:
A channel is a namespace of image processing, and the management entity for billing, permission control, logging, and other advanced functions.
A Channel can have multiple styles. Currently, a Channel is allowed to have up to 50 styles.
A style can be applied to change all Objects in a Channel.
For example, if style abc is in Channel A and the style content is 100w.jpg (scaled to 100 in width and saved as a .jpg file), style abc can be applied to all the Objects in Channel A to scale them to 100 in width and saved them as .jpg files.
A style is only effective within a Channel, that is, the Objects in Channel A cannot use any style in Channel B.
The URL format for image processing by style is as follows:
http://userdomain/object?x-oss-process=style/name

Related

Cognitive Image Search API - Get only transparent background images

I am currently trying to use the Cognitive Image Search API - V5.
My question is quite simple, is there a way to filter the result of the request to get only images with transparent background ? (Not only filtering by file extension, some png are not transparent). Obviously I didn't find anything useful in the doc or on the web.
I would appreciate if you guys could give me some tips!
This particular search parameter is not available. the current filters that are available are listed below.
aspect—Filter images by aspect ratio (for example, standard or wide screen images)
color—Filter images by color or black and white
freshness—Filter images by age (for example, images discovered by Bing in the past week)
height—Filter images by height
imageContent—Filter images by content (for example, images that show only a person's face)
imageType—Filter images by type (for example, clip art or animated GIFs)
license—Filter images by the type of license that applies to the image
size—Filter images by size, such as small images up to 200x200 pixels
width—Filter images by width
You can see further information for Bing Image Search query parameters here

Where are the specs of HTML canvas globalCompositeOperation modes?

I've been wading through terabytes of erudite essays on various aspects of canvas blending modes lately, and even found beautiful test pages like this one.
However, I could only find the vaguest description of what the different modes do, on a pixel-per-pixel basis, including the way alpha channel is used either in selecting src/dest pixels or in combining src/dest values.
Could a kind soul point me to a reliable source?
Formal specifications for the HTML5 canvas 2d context are published by the WhatWG and the World Wide Web Consortium.
The WhatWG references a separate spec for the composite operation values.
The W3 defines it as follows:
source-atop
A atop B. Display the source image wherever both images are opaque. Display the destination image wherever the destination image is opaque but the source image is transparent. Display transparency elsewhere.
source-in
A in B. Display the source image wherever both the source image and destination image are opaque. Display transparency elsewhere.
source-out
A out B. Display the source image wherever the source image is opaque and the destination image is transparent. Display transparency elsewhere.
source-over (default)
A over B. Display the source image wherever the source image is opaque. Display the destination image elsewhere.
destination-atop
B atop A. Same as source-atop but using the destination image instead of the source image and vice versa.
destination-in
B in A. Same as source-in but using the destination image instead of the source image and vice versa.
destination-out
B out A. Same as source-out but using the destination image instead of the source image and vice versa.
destination-over
B over A. Same as source-over but using the destination image instead of the source image and vice versa.
lighter
A plus B. Display the sum of the source image and destination image, with color values approaching 255 (100%) as a limit.
copy
A (B is ignored). Display the source image instead of the destination image.
xor
A xor B. Exclusive OR of the source image and destination image.
vendorName-operationName
Vendor-specific extensions to the list of composition operators should use this syntax.

SSRS can't properly render *some* images within PDF

I have a report that renders images (jpg) that have been collected from various sources. This works fine within the report viewer, and when exporting via Excel.
However, when exporting to PDF, about 5% of the images are rendered incorrectly as can be seen below, with the original on the left, and what is rendered on the right;
I find that if I open up one of these images in mspaint, and just click save, on the next report-run the image is now rendered correctly.
Are there any rules as to what image properties/format are valid for SSRS to render the image correctly within a PDF? Essentially I'd like to somehow find these images that will render incorrectly before the report is run and fix them prior...
Current Workaround
I never ended up getting SSRS to display the the problem images as they were, however, determining before running the report which images would be included in the non-displayable set so they could be converted to a supported format (automatically) was also a solution.
In my case, all images were supplied via users uploading to a website, so I was able to identify and convert images as they arrived. For all existing images, I was able to run a script that identified the problem images and convert them.
Identifying problem images
From the thousands of images I had, I was able to determine that the images that wouldn't render correctly had the following properties:
Image had CMYK colorspace or;
Image had extended color profiles or;
Both of the above
Converting an image
I was originally using the standard .NET GDI (System.Drawing) to manipulate images however the API is often prone to crashes (OutOfMemoryException) when dealing with images that have extra data. As such, I switched to using ImageMagick where for each of the identified images I:
Stripped the color profiles and;
Converted to RGB
Note that the conversion to RGB from CMYK without stripping the color profiles was not enough to get all images to render properly.
I ended up just doing those items on every image byte stream I received from users (without first identifying the problem) before saving an uploaded image to disk. After which, I never had the rendering problem again.
Because of the way the output looks I would say those JPEG images have CMYK colorspace but the SSRS assumes they use RGB colorspace and sets the wrong colorspace in PDF.
If you can post a JPEG image and a sample PDF I can give you more details.
I've had exactly the same problem with an image rendering correctly on screen but appearing like the one in the question when I exported the report to PDF. Here's how I solved it.
The Problem
The first clue was this article I came across on MSDN. It seems that regardless of the original image density, the PDF renderer in SSRS resizes all images to 96 DPI. If the original size of the image is larger than the size of the page (or container), then you will get this problem.
The Solution
The solution is to resize the source image such that it will fit on your page. The requires a little calculation depending on your page size and margin settings.
In my case, I'm using A4 paper size, which is 21cm by 29.7cm. However, my left margin is 1.5cm, and my right margin is 0.5cm, for a total inner width of 19cm. I allow an extra 0.5 cm as a margin of error, so I use an inner width of 18.5cm.
21 cm - 1.5 cm - 0.5 cm - 0.5 cm = 18.5 cm
As noted before, the resolution generated by the PDF renderer is 96 DPI (dots per inch). For those of us not in the United States or Republic of Liberia, that's 37.79 DPC (dots per centimetre). So, to get our width:
18.5 cm * 37.79 dpc = 699 pixels
Your result may be different depending on (1) the paper size you are using, and (2) the left and right margins.
As the page is higher than it is wide, we need only resize the width while keeping the image proportional. If you're using a paper size which is wider than it is tall, you'd use the length instead.
So now open the source image in Paint (or your image editor of choice), and proportionally resize the image to the desired width (or length) in pixels, save it, import it into your container, and size the image visually with respect to the container. It should look the same on screen, and now render correctly to PDF.
This is an issue reported to Microsoft Connect.
From SSRS 2008 How to get the best image quality possible?:
The image behavior you see in PDF is a result of some image conversions that the PDF renderer does, based on how the PDF specification requires that serialize images into PDF.
We know it's not ideal, and we classify the loss of image quality as a product issue. Therefore, it's difficult to really say what to do to get the best quality image.
Anecdotally, I have heard that customers have good results when the original image is a BMP

Disable color correction in Firefox programatically per image?

this question is in close relation to Firefox 3.5 color correction hack?
The situation I have is that there's a canvas game of mine, and the images that are used in it carry additional information about their shape, connection points etc. This information is stored in the PNG image itself, using meaningful colours (eg RGB(255,255,0) for connection point).
Loading element and painting on the canvas creates Image object, img.src is set, and in img.load function I preprocess image data reading the sensitive information (and removing sensitive pixels from the image data before painting to canvas).
The problem: In FF, the pixel which was supposed to be 255,255,0 is actually 255,254,0. I don't have problems with FF color correction (I don't care if the displayed image has right colors, or slightly modified), but I'd expect that getting image data gives me uncorrected data. I'm looking for a solution which would not involve changing images on the server. Is there some way? Eg.
img.setColorProfile(), or
img.disableColorCorrection(), or
img.getImageData(disableColorCorrection) or img.getImageData(colorProfile)?
The problem might have do more with image loading than image drawing.
I think the proper solution is to strip out color profile information from the images (which you seem to want to aovid). If possible server another image resources for Firefox if you cannot need to have the original data intact.
http://f6design.com/journal/2006/12/01/fixing-png-gamma/
Also, you could decode PNG immages in pure Javascript if the server is co-operate and allows CORS and AJAX loading of the images. You decode the image in Javascript using png.js and create a source <canvas> from the image data (instead of <img>). This way it's you in the control what RGB values comes out from each PNG pixel.
https://github.com/devongovett/png.js

Image and video fullscreen?

)
I have a application to show some videos and images.. like a presentation.. The images have different resolution's and the videos to. I want to put the images and the videos in full screen mode but without lose quality.. The rotation of screen is fine, but the media content does not appear like they should..
Basically i want to show the images centered in vertical and horizontal without lose quality..
Suggestions?
For the video I would recommend using a MediaElement with the Stretch attribute set to 'Uniform'. 'Uniform' takes up all the space that you give the control but it ensures that the video maintains its aspect ratio. You should still have all the qaulity possible because the stretching happens on the GPU and it does a great job. You can see an example here:
http://msdn.microsoft.com/en-us/library/system.windows.controls.mediaelement.aspx
Now, if you want the video to only scale up to it's orignial size but not get blown up any larger, then just set the Stretch property to 'None'.
The Image control works the same way and also has the same Stretch property. See the Image class documentation and sample here:
http://msdn.microsoft.com/en-us/library/system.windows.controls.image(v=VS.95).aspx
Did you try the MediaElement API and the NaturalVideoHeight and NaturalVideoWidth properties?

Resources