How to compress JPGs in Appcelerator Titanium - mobile

I need to take pictures with the device camera in Appcelerator Titanium and then compress the resulting image. It's already possible to save as .png and .jpg of any dimensions with the existing SDK, but no way I can see yet to apply compression to the .jpg (currently saves with no compression at large file sizes). Is there a way to do this in later Titanium SDKs and/or what are the best third-party modules for doing this (for both iOS and Android)?

I use this module https://github.com/appcelerator-modules/ti.imagefactory
to compress image and it's work fine
var compressQuality = 0.8;
//compression quality 80%
blob = ImageFactory.compress(blob, compressQuality);
blob = ImageFactory.imageAsResized(blob, {
height : outputHeight,
width : outputWidth
});

Related

I need to resize the images in my project react + gatsby

My application web its so slow, i need to improve for what i going to resize the size of my images.
i should to resize the images before to upload? or should i use this plugin gatsby-plugin-image (https://www.gatsbyjs.com/plugins/gatsby-plugin-image/)?
gatsby-plugin-image
Adding responsive images to your site while maintaining high
performance scores can be difficult to do manually. The Gatsby Image
plugin handles the hard parts of producing images in multiple sizes
and formats for you!
what is better?
if i choose the first one option my code will be like this: with this library https://www.npmjs.com/package/react-image-file-resizer
const resizeFile = (file) => new Promise(resolve => {
Resizer.imageFileResizer(file, 300, 300, 'JPEG', 100, 0,
uri => {
resolve(uri);
}, 'base64' );
});
It would depend on where are you using react-image-file-resizer package. For what is worth, I would say that is not worth it at all. Gatsby handles the image treatment/resizing/transforming process during the build process using some Python-based code, which runs in the server directly (not in the front-end like the library you've shared) so the performance won't be affected. Of course, this can increase the build time, but doesn't affect the PageSpeed Insights score, in fact, otherwise, because of that performance, you images will be optimized as soon as they are served, unlike react-image-file-resizer, where it's React-based code that triggers all the image treatment.
That said, your image optimization should be done by your queries (where you fetch those images), taking fluid or fixed sizes (in v2) or StaticImage or GatsbyImage (in v3), lifted with the needed sizes to serve the images that you need in each device because Gatsby will serve the image sizes that you are telling to, so if you need some treatment should be done there.

How to implement video with transparent background in react-native

How can i implement a Video Player with transparent background in React-native? The video is saved with the extension .mov (only extension found to support transparent background).
Used react-native-player but it only renders a back screen.
Tried with https://www.w3schools.com/html/mov_bbb.mp4 both loaded locally and via uri and it worked.
Platform target: iOs
I needed same thing and tried many different methods and my conclusion is transparent movie file is not an accepted practice/standard. Only apple quicktime supports it.
Here are few workarounds I tried and made it partially work with a lot of performance challenges.
Best working method is to export all mov frames (with whatever frame rate is acceptible for you - for me I was trying to render something that was going to be exported as gif, so even 15 fps worked for me). Export movie frames as transparent png. Ffmpeg can easily do that.
Then either with simple loop, load and update frames from the js code. This is still very challenging because loading each frame in an image view from jsbundle simply does not catch up with your frame rate needs. As far as my experience, I only saw low single digit frame rates with loading resources from jsbundle. On the other hand, there is a solution for this. You can put your png files in xcassets in ios/xcode, and drawables in android. Then use { uri: 'filename' } to load resources from native apps. This resulted very good quality and speed for me on iOS even for 20-30 second video lengths at 1080p quality. Unfortunately this suffered from memory issues and didn't work on Android - Android only handled 100something frame for me. If you have more than 150-200 frames for your movie in total, regardless of fps, it will hit to the memory limits. I spent more than a week to research alternative ways to overcome memory issue, load many large bitmaps in memory for sequence display them in the app. There are theoretical methods to utilize memory on android without heap size limitations but I found it too low level and beyond my android/java knowledge.
Another path I experimented without success was webM format. It's webp format from google that is supported with some push but I couldn't find enough resources online about webm playback. I succeeded to play a webm file but it just works like gif players which almost all of them don't have clear ways to support transparent animated gifs. So I wasn't able to get to a solution with webp/m as well.
Right now I am trying to fake the transparent portions of my video with other RN animated elements over the video.
By the way, I tried most of these solutions natively on iOS and Android separately and both platforms had its own problems with them.

how to export a mapbox studio map as .mbtiles file

So I'm guessing the answer to this is "no", but is there any way to export a map I've designed online with mapbox studio (https://www.mapbox.com/studio/) into a .mbtiles file so I can host it myself?
Honestly, I'd be willing to pay money for this (saving me the trouble of getting a world .pbf file and getting it into a postgresql db is really a pain, especially with a mediocre computer like mine)
It sounds like maybe there used to be a way to do this, but as of now it looks like they've taken away this ability. I can see a lot of different ways to use a map I've created, but everything forces me to use mapbox as the hosting service... it seems there's no way to download a map I've created.
I think your assumption is correct. It does seem MapBox wants you to use their APIs and API keys.
However, there is a partial solution with raster tiles if you can fallback to that. Or you can get vector mbtiles from OSM data instead of from mapbox servers.
mapbox offline support for android/ios
I've contacted mapbox support in April 2017, and what I've been told is that although the style files that you can download from MapBox studio don't contain tiles, there's a way to have them render offline on Android/iOS.
If you would like to use Mapbox maps offline, you would need to follow the examples shown for Android or iOS, depending on your platform. Essentially, the mobile SDKs take in a style URL that points to your custom style created in Mapbox Studio, and the SDKs handle the downloading of all other resources needed to keep the map offline (fonts, icons, tilesets, etc). Check out our guide on offline maps to read more about how this works.
Links:
Offline Maps with MapBox
Mapbox Android-SDK Offline example
Mapbox iOS-SDK Offline Example
From a quick look at the example code, it would seem that the downloading of the tiles is done within the App, but done ahead of time, for instance just after you install the app and you still have
network connectivity. I don't immediately see whether or not your Mapbox API keys are involved at all in this download, with respect to your billing concern. There is a 6000 offline tile limit per offline region.
Not for desktop: The site also mentions that offline is not an option for MapboxGl-JS, so you'd have to hack it up to make your offline region available on desktop web browsers.
mapbox studio export as mbtiles...
There was supposedly a non obvious option in settings to download your source as an mbtiles file in mapbox studio classic. A mapbox classic issue on github has a screenshot of where the button should be. It's possible that option is gone now.
That github project, https://github.com/klokantech/vector-tiles-sample, provides links to projects/tools that can break the mbtiles file into its contained pbf files, which are a protobuf compressed format for each vectorial tile (https://github.com/mapbox/mbutil). Slightly outdated.
An approach which might otherwise work, is to cache the network requests ahead of time for each tile retrieved from MapBox, and then in your APP proxy the requests to your cache. I'm not sure whether that's against the ToS though. You'd probably have to do it programmatically with all XYZ coords you wish to cache.
Taking a dive with tippecanoe to produce vector tiles
You can create vector tiles with tippecanoe (and host them yourself). It's not MapBox, I know. But it might get your farther in the long run.
Nice short blog article about it: http://fuzzytolerance.info/blog/2017/02/02/Making-your-own-tiles-with-Tippecanoe/
The mbtiles you create, you can layer them, and possibly style them with the open source maputnik (which is somewhat like the style editor of mapbox). Then you take serve mbtiles with your own server, and plug in your style into mapboxGL-js or openlayers.
TileMill -- (.mbtiles with raster tiles) fallback
There is TileMill which is still available (but deprecated), runs on the desktop, and will allow you to create maps from shapefiles (e.g. you can get openstreetmap shapefiles for single cities at https://mapzen.com/data/metro-extracts/ ).
TileMill, will give you a mbtiles file at the end of the process. Although, that mbtiles contains raster tiles, not vector tiles. Vector tiles can be styled dynamically so it's nice on mobile when you want to accommodate various situations with fonts or adapt lighting.
Raster tiles might suffice, because in your app you probably will be able to render other interactive objects on top of that base layer. OpenLayers is one portable framework where you'd be able to do that, for instance -- allowing the user to draw objects or click points of interest that you've loaded from a database separately from the map data.
Get OSM-based vector tiles instead of mapbox
There seems to be an alternative maker of Vector tiles now, http://openmaptiles.org (used to be http://osm2vectortiles.org ).
You can go here, and download an mbtiles file for a city of your choice for instance: https://openmaptiles.org/downloads/#city , then serve that file (locally) for your app with a tile server. (or use one of the tools mentioned above to break it into the individual pbf files and read the files from local disk / memory)
With this approach, you combine a vector mbtiles from OSM, with the style you've created in mapbox studio (mapbox studio lets you download a zip file with your .json style in it), and you can still use MapBoxGL to display it.
There's Maputnik http://maputnik.com/ which you can use to edit a mapboxgl style file (the editor works with local storage). and there's presumably https://github.com/boundlessgeo/ol-mapbox-style which allows you to convert that style into a piece of code suitable for OpenLayer's style API.
As far as I know Mapbox does not provide map downloads. You could download vector maps directly using their vector tiles API and be charged against your vector tile count. 200K tiles are free per month. In my experimentation, 80K tiles represent about 200 sqaure km of area. So you'd run out of free tiles very quickly for large areas and would have to pay 1$ per about every 10km more of square km area. (all very approx values based on nominal observation). Also, these leaves the challenge to actually package the .mvt files into a MBTiles format.
I suggest an alternative way instead.
You can create MBTiles from any .osm.pbf file using this tool - https://github.com/systemed/tilemaker
Download .osm.pbf file from Geofabric. To download for a custom area, you can use Protomaps or BBBike Extract
Download tilemaker
Execute the following command
tilemaker --input netherlands.osm.pbf --output netherlands.mbtiles --process resources/process-openmaptiles.lua --config resources/config-openmaptiles.json
You can read more about it in this blog post - https://blog.kleunen.nl/blog/tilemaker-generate-map
To use the same style that you created in Mapbox Studio, you can download your style's JSON file by clicking on Share -> Download. This zip will contain your JSON file which describes all the colors, etc you customised.
If you are planning to show this MBTile on Android app, you'll just have to embed this JSON that you downloaded and the MBTiles file in the app and point the JSON to the MBTiles file. I've written how to do this in this blogpost. I tried to make the JSON work but only partly succeed after some edits. However ideally it should work since its based on the openmaptiles schema.

Insert a image in imageview with url into sqlite DB without BLOB

I need to insert an image into a imageview with url into sqlite DB without using the BLOB, is possible??
Thanks in advance
Short answer: I am not aware of any way to save images in SQLite without using BLOBs, and BLOBs of images can be too large for the server to handle smoothly. But I won't claim to have thorough experience with SQLite, so there's a good chance I'm missing something.
Depending on what other resources are at your disposal, one solution would be to just store the url for the image in a TEXT type, but save the image in some other file system. Then when you want to display the image, query the database to get the address (plus whatever other relevant info), isolate it from the results, and query the file system for the image. Implementing this pattern will really depend on the environment your system will be working in; if it's an Android device, you can probably just refer to the filepath it started at, or save it to a dedicated folder; if it's a web interface, the images would most easily be saved as a sub-folder next to the web page(s) that use the images.

Is my .XAP file too big? and if so how do i make it smaller?

I'm currently doing some work on a silverlight LOB application i wrote for a customer..
When i deploy i can't help noticing how big the xap file is (4mb) and considering it's not a massive app it seems a little unusual.
I am using the telerik silverlight toolkit (but only including the required themes - 2 I think)..
There's about 1mb of images (which is maybe a bit too much for a LOB app)..
Is this average for a silverlight application?
Whats the average size of your xap files?
How would I go about "minifying" or compressing my xap file?
If you open the .xap file with an archive reader like 7-Zip, or rename it to .zip and open it, you can get an idea of where the size is coming from.
You can cut down on the size of the file by removing any References that aren't used. If you're not sure if something is used or not, remove it and see if the app still builds. If not, put it back in.
In your Silverlight project's Properties, in the Silverlight section, you can check the "Reduce XAP size by using application library caching" checkbox to have it move some of the DLLs out to separate .zip files instead of being included in the XAP. That way, if your app changes, your users don't have to download all of the included DLLs again.
If it's still too large for your tastes, you might want to look at moving the images out of the .xap file.
You can minimize the xap file by:
Reduce image sizes
Implement styles using xaml instead of using static images
Remove images - I never did it in my applications, but you can specify an image url instead of embedding it inside your xap file, this would make your xap file smaller, but will have a minor ui-effect as the images will take some time (depending on the client's network) to download the images.
Split your application into multiple xap files and dynamically load the required xap modules (frameworks such as MEF and PRISM will make it very easy)
A quick way to make your xap file size smaller is to check the 'Reduce XAP size by using application library caching' checkbox in the Silverlight tab of you project. For more info on what it does : How to: Use Application Library Caching

Resources