Coder Social home page Coder Social logo

tidev / ti.imagefactory Goto Github PK

View Code? Open in Web Editor NEW
68.0 26.0 52.0 5.51 MB

The ImageFactory Module for Appcelerator Titanium

License: Apache License 2.0

JavaScript 16.72% Python 6.46% Java 46.20% Objective-C 30.62%
imagefactory ios android compress rounded-corners rotate-image titanium-module

ti.imagefactory's Introduction

Titanium ImageFactory Module

Ti.ImageFactory provides a set of image transformation functions including the ability to scale, crop, and compress images. Additionally, this module offers the functionality of adding alpha channels and transparent borders.

Getting Started

View the Using Titanium Modules document for instructions on getting started with using this module in your application.

Accessing the Ti.ImageFactory Module

To access this module from JavaScript, you would do the following:

const ImageFactory = require('ti.imagefactory');

Methods

imageWithRotation(blob, options)

Creates a new image by creating a copy of the given image that is rotated.

Arguments

  • Image blob[blob]: Image to transform
  • Options[dictionary]: A dictionary specifying the options for the transformation
    • degrees[int]: The degrees to rotate the image

imageWithAlpha(blob, options)

Creates a new image by creating a copy of the given image, adding an alpha channel if it doesn't already have one.

Arguments

  • Image blob[blob]: Image to transform
  • Options[dictionary]: A dictionary specifying the options for the transformation
    • iOS: Currently there are no properties for this method -- specify an empty dictionary
    • Android: format [int]: The output format: ImageFactory.JPEG, ImageFactory.PNG, ImageFactory.WEBP (default: ImageFactory.JPEG)
    • Android: quality[float]: The quality of the resulting JPEG or WebP image, expressed as a value from 0.0 to 1.0. The value 0.0 represents the maximum compression (or lowest quality) while the value 1.0 represents the least compression (or best quality). (default: 0.7)

imageWithTransparentBorder(blob, options)

Creates a new image by creating a copy of the given image, adding a transparent border of the given size around its edges. The size of the image will be expanded by the specified border size.

Arguments

  • Image blob[blob]: Image to transform
  • Options[dictionary]: A dictionary specifying the options for the transformation
    • borderSize[int]: The size of the border (default: 1)
    • Android: format [int]: The output format: ImageFactory.JPEG, ImageFactory.PNG, ImageFactory.WEBP (default: ImageFactory.JPEG)
    • Android: quality[float]: The quality of the resulting JPEG or WebP image, expressed as a value from 0.0 to 1.0. The value 0.0 represents the maximum compression (or lowest quality) while the value 1.0 represents the least compression (or best quality). (default: 0.7)

imageWithRoundedCorner(blob, options)

Creates a new image by creating a copy of the given image with rounded corners.

Arguments

  • Image blob[blob]: Image to transform
  • Options[dictionary]: A dictionary specifying the options for the transformation
    • borderSize[int]: The size of the border (default: 1)
    • cornerRadius[int]: The radius of the corner edges (default: 0)
    • Android: format [int]: The output format: ImageFactory.JPEG, ImageFactory.PNG, ImageFactory.WEBP (default: ImageFactory.JPEG).
    • Android: quality[float]: The quality of the resulting JPEG or WebP image, expressed as a value from 0.0 to 1.0. The value 0.0 represents the maximum compression (or lowest quality) while the value 1.0 represents the least compression (or best quality). (default: 0.7).

imageAsThumbnail(blob, options)

Creates a new image by creating a copy of the given image that is squared to the thumbnail size.

Arguments

  • Image blob[blob]: Image to transform
  • Options[dictionary]: A dictionary specifying the options for the transformation
    • size[int]: The size of the thumbnail (default: 48)
    • borderSize[int]: The size of the border (default: 1)
    • cornerRadius[int]: The radius of the corner edges (default:0)
    • iOS: quality[int]: The interpolation quality. One of the following constants (default: imagefactory.QUALITY_HIGH)
      • imagefactory.QUALITY_DEFAULT
      • imagefactory.QUALITY_NONE
      • imagefactory.QUALITY_LOW
      • imagefactory.QUALITY_MEDIUM
      • imagefactory.QUALITY_HIGH
    • Android: quality[float]: The quality of the resulting JPEG or WebP image, expressed as a value from 0.0 to 1.0. The value 0.0 represents the maximum compression (or lowest quality) while the value 1.0 represents the least compression (or best quality). (default: 0.7)
    • Android: dither[boolean]: Indicates if dithering should be applied while scaling. (default: false)
    • Android: format [int]: The output format: ImageFactory.JPEG, ImageFactory.PNG, ImageFactory.WEBP (default: ImageFactory.JPEG)

imageAsResized(blob, options)

Creates a new image by creating a copy of the given image that is rescaled to the specified size.

Arguments

  • Image blob[blob]: Image to transform
  • Options[dictionary]: A dictionary specifying the options for the transformation
    • width[int]: The width of the new image (default: image width)
    • height[int]: The height of the new image (default: image height)
    • iOS: hires[boolean]: Create a hires image (for Retina displays only)
    • iOS: quality[int]: The interpolation quality. One of the following constants (default: imagefactory.QUALITY_HIGH)
      • imagefactory.QUALITY_DEFAULT
      • imagefactory.QUALITY_NONE
      • imagefactory.QUALITY_LOW
      • imagefactory.QUALITY_MEDIUM
      • imagefactory.QUALITY_HIGH
    • Android. format [int]: The output format of the image: either ImageFactory.PNG or ImageFactory.JPEG (default: ImageFactory.JPEG)
    • quality[float]: The quality of the resulting JPEG or WebP image, expressed as a value from 0.0 to 1.0. The value 0.0 represents the maximum compression (or lowest quality) while the value 1.0 represents the least compression (or best quality). (default: 0.7)

imageAsCropped(blob, options)

Creates a new image by creating a copy of the given image that is cropped to the specified bounds.

Arguments

  • Image blob[blob]: Image to transform
  • Options[dictionary]: A dictionary specifying the options for the transformation
    • width[int]: The width of the new image (default: image width)
    • height[int]: The height of the new image (default: image height)
    • x[int]: The x-coordinate of the upper-left corner of the bounds (default: image center - width / 2)
    • y[int]: The y-coordinate of the upper-left corner of the bounds (default: image center - height / 2)
    • Android: format [int]: The output format: ImageFactory.JPEG, ImageFactory.PNG, ImageFactory.WEBP (default: ImageFactory.JPEG)
    • Android: quality[float]: The quality of the resulting JPEG or WebP image, expressed as a value from 0.0 to 1.0. The value 0.0 represents the maximum compression (or lowest quality) while the value 1.0 represents the least compression (or best quality). (default: 0.7)

imageTransform(blob, options)

Creates a new image by applying a sequence of transformations to the image.

Arguments

  • Image blob[blob]: Image to transform
  • Transform[dictionary]: A sequence of transform specifications. Transforms are listed as additional parameters to the function and are applied in the order specified. Each transform is a dictionary with the options described above for each transform along with an additional 'type' property included with each dictionary of transform options.
    • type[int]: The identifier of the transform to apply. One of the following constants
      • imagefactory.TRANSFORM_CROP
      • imagefactory.TRANSFORM_RESIZE
      • imagefactory.TRANSFORM_THUMBNAIL
      • imagefactory.TRANSFORM_ROUNDEDCORNER
      • imagefactory.TRANSFORM_TRANSPARENTBORDER
      • imagefactory.TRANSFORM_ALPHA
    • options as described in the above transforms

compress(blob, quality [, format])

Creates a new image by creating a copy of the given image and applying the specified compression quality.

Arguments

  • Image blob[blob]: Image to compress
  • Compression Quality[float]; The quality of the resulting JPEG or WebP image, expressed as a value from 0.0 to 1.0. The value 0.0 represents the maximum compression (or lowest quality) while the value 1.0 represents the least compression (or best quality).
  • Android (optional): format [int]: The output format: ImageFactory.JPEG, ImageFactory.PNG, ImageFactory.WEBP (default: ImageFactory.JPEG)

compressToFile(blob, quality, fileUrl)

Compresses the given blob to an image file.

Arguments

  • Image blob[blob]: Image to write to file
  • Compression Quality[float]; The quality of the resulting JPEG or WebP image, expressed as a value from 0.0 to 1.0. The value 0.0 represents the maximum compression (or lowest quality) while the value 1.0 represents the least compression (or best quality).
  • fileUrl [string]: File path to write the image to. Supports extensions ".png", ".jpg", and ".jpeg". Android also supports ".webp".

Usage

See example.

License

Apache 2

Copyright

2011-present by Axway Appcelerator

ti.imagefactory's People

Contributors

adesugbaa avatar anil-shukla-axway avatar ashcoding avatar caspahouzer avatar cb1kenobi avatar collinprice avatar dependabot-preview[bot] avatar dependabot[bot] avatar ewanharris avatar garymathews avatar hansemannn avatar ingo avatar jonalter avatar jquick-axway avatar m1ga avatar muhammaddadu avatar pec1985 avatar saumya-rai-axway avatar sgtcoolguy avatar ssjsamir avatar stephenfeather avatar vijaysingh-axway avatar ypbnv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ti.imagefactory's Issues

Android: (Rare) ANR when using ImageFactory.compress()

In some cases, the compress-API can cause an ANR due to draining memory. The solution should be to either make it fully async (via background thread) or use a different, more stable, compression algorithm. Maybe there are advancements in the Android world since the initial release.

Maybe use Compressor for all compression-related tasks?

ANR log:

main (native):tid=1 systid=10769 
#00 pc 0x86b8c libc.so (syscall + 28)
#01 pc 0x1b092c libart.so (art::ConditionVariable::WaitHoldingLocks(art::Thread*) + 148)
#02 pc 0x3f8964 libart.so (art::JNI<false>::SetByteArrayRegion(_JNIEnv*, _jbyteArray*, int, int, signed char const*) + 504)
#03 pc 0x3410c0 libhwui.so (SkJavaOutputStream::write(void const*, unsigned long) + 92)
#04 pc 0x55825c libhwui.so (sk_empty_output_buffer(jpeg_compress_struct*) (.llvm.15802703823201869038) + 48)
#05 pc 0x12ac8 libjpeg.so (encode_mcu_huff + 820)
#06 pc 0xdcc0 libjpeg.so (compress_output + 504)
#07 pc 0xb2dc libjpeg.so (jpeg_finish_compress + 312)
#08 pc 0x558e7c libhwui.so (SkJpegEncoder::onEncodeRows(int) + 296)
#09 pc 0x558fa4 libhwui.so (SkJpegEncoder::Encode(SkWStream*, SkPixmap const&, SkJpegEncoder::Options const&) + 112)
#10 pc 0x557ef8 libhwui.so (SkEncodeImage(SkWStream*, SkPixmap const&, SkEncodedImageFormat, int) + 64)
#11 pc 0x36375c libhwui.so (android::Bitmap::compress(SkBitmap const&, android::Bitmap::JavaCompressFormat, int, SkWStream*) + 292)
#12 pc 0x3635a8 libhwui.so (android::Bitmap::compress(android::Bitmap::JavaCompressFormat, int, SkWStream*) + 84)
#13 pc 0x338728 libhwui.so (Bitmap_compress(_JNIEnv*, _jobject*, long, int, int, _jobject*, _jbyteArray*) + 136)
       at android.graphics.Bitmap.nativeCompress(Native method)
       at android.graphics.Bitmap.compress(Bitmap.java:1779)
       at ti.imagefactory.ImageFactoryModule.compress(ImageFactoryModule.java:316)

Dist for ios

Where is dist folder/file for ios? how do i install it without zip package in ios?

iOS 64-bit distribution build?

I guess this module was recently updated for iOS 64-bit support (v1.2.0), but the zip file in the folder is still v1.1.1. Can that old zip file (ti.imagefactory-iphone-1.1.1.zip) be removed and a new one added for 1.2.0? Thanks!

Module not listed

I have imported the module archive and also verified in the home location of modules in MAC OS. It is available but it is not listed in the module list when I click '+' in module section in tiapp.xml

Appcelerator Studio, build: 4.8.1.201612050850

And I manually added from the xml file

<module platform="android">ti.imagefactory</module>

it says module is not supported with Titanium SDK 5.1.0GA

Crop image method is not working as expected.

Hi Team,

My requirement is to take a image using camera and i will pass dimensions to image factory module using imageAsCropped method. So in return module has to provide me the image cropped with the dimensions specified. But the image cropped by this module is blurred and zoomed to fit the dimensions.

Thanks
Nag

Android: PX dimension support for Android

In the iOS module the imageAsResized accounts for DP. Not Android. I'm resizing to 300x300 and the image is blurry. I had to manually account for the dp before sending to imageAsResized.

Is this intended? Seems annoying to have the modules be different.

Error with remote image

Hi,

When I'm trying to run a image through Imagefactory, i get this error:

[ERROR] [iphone, 8.1, undefined] {
"nativeLocation": "+TiImagefactoryModule imageTransform:withArgs:",
"message": "Invalid type passed to function",
"nativeReason": "expected: TiBlob, was: String",
"line": 57,
"column": 55,
"stack": "[native code]\nonload"
}

Im using your latest version with 64 bit, and running 3.5.0 SDK. Any suggestions?

After compress the image clarity and quality missed?

Hi All,

I am using this module for compress the image.
After compressed that image it is giving less quality and clarity compared with original image.

Can any help me out, how to get image with full clarity and quality after compress or crop of original image also

iOS .imageAsResized() on image/jpeg generates a blob with mimeType image/png

On iOS .imageAsResized() on image/jpeg generates a blob with mimeType image/png

blob = ImageFactory.compress(blob, 0.8, ImageFactory.JPEG);

// now blob has mimeType image/jpeg

blob = ImageFactory.imageAsResized(blob, { width: 1000, height: 1000, quality: 0.8 }, ImageFactory.JPEG);

// now blob has mimeType image/png

P.S. The third parameter on iOS is not supported yet

64 bit support?

Now that App Store requires 64 bit support, is there someone available for making it?

Very unstable on Android

For certain images that are either big or with many colors this module crash, I tried using try/catch which sometimes catch the error and sometimes just crash the complete app.
(Tried version 2.2.1) Gist: https://gist.github.com/rpavez/45ec3a6394d9a41baad8

I really would appreciate some help, recommendations to fix the issue or other similar module.

Android: java.lang.NullPointerException

I am using Titanium SDK 4.1.0GA and ti.imagefactory 2.2.1

but my console print this:

at ti.imagefactory.ImageFactoryModule.compress(ImageFactoryModule.java:251)
[WARN] : W/System.err: at org.appcelerator.kroll.runtime.v8.V8Object.nativeFireEvent(Native Method)
[WARN] : W/System.err: at org.appcelerator.kroll.runtime.v8.V8Object.fireEvent(V8Object.java:62)
[WARN] : W/System.err: at org.appcelerator.kroll.KrollProxy.doFireEvent(KrollProxy.java:908)
[WARN] : W/System.err: at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1137)
[WARN] : W/System.err: at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:348)
[WARN] : W/System.err: at org.appcelerator.titanium.proxy.TiWindowProxy.handleMessage(TiWindowProxy.java:102)
[WARN] : W/System.err: at ti.modules.titanium.ui.WindowProxy.handleMessage(WindowProxy.java:428)
[WARN] : W/System.err: at android.os.Handler.dispatchMessage(Handler.java:98)
[WARN] : W/System.err: at android.os.Looper.loop(Looper.java:136)
[WARN] : W/System.err: at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:112)

My code en .js is:

var _imageFactory = require('ti.imagefactory');

function(imagen) {ย 
return _imageFactory.compress(imagen, 0.60);
};

cant find module: ti.imagefactory for architecture x86_64

Hi I keep getting the following error (cant find module: ti.imagefactory for architecture x86_64). I have followed every suggested answer I could possibly find on the net, including editing the manifest file, editing the module setting in xcode, copy the url straight from the download link and pasting it into titaniums module insert. It appears in tiapp.xml but still nothing.

I must add that this happens with all modules im using from github, so im assuming that if i solve this problem once, I should then be able to replicate the solution for them all. This how now held up my app development at this stage untill I can resolve this issue and is really frustrating, I would appreciate if anyone had any clear concise proven solutions.Many thanks in advance????

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.