ArticleImage
A class for images in WeChat articles.
You'll find this in the returned array of WeChatArticle#getMedia. You
can use instanceof
to find out if that element is an image.
This library itself doesn't handle images, since many problems are closely
related to your implementations. But we do provide a set of API for easier
image handling. You can get the URL, remove it out of the article and set a
new URL to where you caches all images. Additionally you can directly stream
the image, and clean up that <img>
for cleaner markup.
Constructor Summary
Public Constructor | ||
public |
constructor($img: $()) Takes a cheerio object( |
Member Summary
Public Members | ||
public |
|
|
public |
|
|
public |
size: * |
|
public |
|
|
public |
|
|
public |
|
Private Members | ||
private |
_$img: * |
|
private |
|
|
private |
|
Method Summary
Public Methods | ||
public |
cleanup() Cleans up the |
|
public |
get$Img(): * Get the underlying $(img). |
|
public |
isRemoved(): * See if you've already removed it. |
|
public |
remove() Removes current image from the HTML. |
|
public |
setUrl(newUrl: *) Set |
|
public |
async stream(): Stream Returns a stream of that iamges. |
Public Constructors
public constructor($img: $()) source
Takes a cheerio object($(someSelector)
). You won't new
one in most cases.
You can get all meta information of this image immediately.
Params:
Name | Type | Attribute | Description |
$img | $() | a cheerio object representing an |
Public Methods
public cleanup() source
Cleans up the <img>
tag. Actually removes all WeChat-defined data-*
,
removes blank style
and class
attributes. And correct the URL to what
you set, in case some of your transformation breaks it.
public get$Img(): * source
Get the underlying $(img). Good for custom tranformations. But don't set src
manually there. Try ArticleImage#setUrl.
Return:
* |
public remove() source
Removes current image from the HTML. This is useful when you decided to remove some decorational gifs & images.
public setUrl(newUrl: *) source
Set src
for the picture. Please make sure this is correctly pointed to
where you store the image.
Params:
Name | Type | Attribute | Description |
newUrl | * |
public async stream(): Stream source
Returns a stream of that iamges. You can use this to persist images to disk.
Return:
Stream |
Example:
(await articleImage.stream()).pipe(fs.createWriteStream('xxx.jpg'))