Giter VIP home page Giter VIP logo

book-content-compressor's Introduction

Book Content Compressor

An API written in ActionScript 3 - Adobe AIR, used to compress book page content by removing whitespace. And optimize book page area by rearranging the position of letters and pictures on the book page so that the page size. books are the smallest. The goal is to save texture when using on mobile.

screenshot

Setup

The Main Class

Class Description
PageConvertor Used with GhostScript Tool. Use convert pdf file then compress
TexturePageGenerator Using for book content compression. Use PNG files
TexturePageReader Used to read compressed files and display book pages

Note: Classes are architected for easy inheritance and plugin implementation

Quick Start

Compress book pages from pdf files

	var pageFormat:IPageFormat = new StarlingEditorFormat();
	var targetFile:File = File.applicationDirectory.resolvePath("input.pdf");			
	var convertor:PageConvertor = new PageConvertor(this);
	// Neu khong dang ky pageFormat thi chi convert thong thuong. Khong sinh ra texture page.
	//convertor.registerPageFormat(pageFormat);
	// Cho phep sinh ra page image ben canh pdf.
	convertor.allowConvertPageImages = true;
	convertor.completed.addOnce(function():void { 
						trace("All page is converted !");
					});
	convertor.eachCompleted.add(function(currentPage:int):void {
						trace("Success converting : " + currentPage);
					})

	//convertor.broswerPDF(2,6,7,8,9); // Compress pages: 2,6,7,8,9
	//convertor.broswerPDF(2, 6, [7, 9], 21, 23); // Compress pages: 2, 6,  7,8,9  , 21 và 23
	convertor.broswerPDF(1);  // Only compress page 1

Compress a book-page PNG file to texture put in a compressed file.

	var pageFormat:IPageFormat = new StarlingEditorFormat();
	var generator:TexturePageGenerator = new TexturePageGenerator(this);
	generator.registerPageFormat(pageFormat);
	  /*
	// Execute the Dispatching when each page is completed. Dispatching before saving as file.
	generator.pagingCompleted.addOnce(...)
	  // The analysis page, which returns the % of objects analyzed out of the total number of objects.
	generator.pagingProgress.addOnce(...)
	  // Checking % number of bytes which is loaded from sample page
	generator.loading.addOnce(...)
	  */
	  // Dispatch when saving the file is done. This is the final stage of the process.
	  generator.saveCompleted.addOnce(function():void { trace("save thanh cong !!!") } );

	  //generator.loadAndBuild("image.png");
	  generator.loadAndBuild("PAGE3.png");

Read and reconstruct a compressed file.

	var pageFormat:IPageFormat = new StarlingEditorFormat();
        var reader:TexturePageReader = new TexturePageReader();
            reader.registerPageFormat(pageFormat);
            reader.completed.addOnce(onParsingCompletedHandler);
            reader.load("image.zip");
     
        function onParsingCompletedHandler():void {
            starling.stage.addChild(reader.getStarlingPage());
        }

Algorithms and AS3 libraries used

  • Simple object detector (Identify objects in an image on a white background)
  • Object Fragment / Defragment (Optimize the number of objects after identification. Make sure the texture area is the smallest)
  • Rectangle Packer (Performance upgrade from an opensource class. Used to arrange objects to take up the least amount of texture space)
  • FZIP
  • SIGNAL
  • Starling
  • Promise (AS3 version)
  • Ghost Script (Converter Tool)

Issues that need upgrading

  • Optimize the removal of whitespace in case there is a border on the whole page
  • Use Worker to optimize compress time.
  • Switch to the server side.
  • Replace Simple Object Detection with Cascade Object Detection (Viola-Jones Algorithm) or just use Tensorflow Object Detection.

@Author: [email protected]

book-content-compressor's People

Contributors

hallopatidu avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.