PHP Classes

PHP Comic Reader Tools: Display images from comic books in HTML pages

Recommend this page to a friend!
  Info   Example   Screenshots   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 111 All time: 9,625 This week: 78Up
Version License PHP version Categories
comicbooktools 1.0.0Custom (specified...7HTML, Graphics, PHP 7
Description 

Author

This package can display images from comic books in HTML pages.

It can read comic book files in cbz or cbr format and extract comic images from them.

The package can also display the extracted comic images as a slideshow in an Web page.

Innovation Award
PHP Programming Innovation award nominee
May 2020
Number 5
Many people like to read comic books. In the past they used to be available only in paper.

Nowadays, many comic books are available as computer file archives that contain digitized versions of the comic book images.

This package provides a solution to access and display files with comic book images.

Manuel Lemos
Picture of Karl Holz
  Performance   Level  
Name: Karl Holz <contact>
Classes: 14 packages by
Country: Canada Canada
Age: 44
All time rank: 44918 in Canada Canada
Week rank: 44 Up1 in Canada Canada Up
Innovation award
Innovation award
Nominee: 9x

Example

<?php
require_once("ComicBookTools.class.php");

$dir = "./comic" ;

if (
array_key_exists('QUERY_STRING', $_SERVER) && isset($_SERVER['QUERY_STRING'])) {
   
$file=rawurldecode(base64_decode($_SERVER['QUERY_STRING']));
   
$cb='';

    if (
is_file($file)){
       
$cb = $file;
    } elseif(
is_file($dir . $file)) {
       
$cb = $dir . $file;
    } else {
        list(
$arc, $img) = explode('|', $file);
        if (
is_file($dir . $arc)) {
           
$cb=$dir . $arc;
           
$cbr = new comic_reader($cb);
           
$cbr->dir=$dir;
           
$cbr->read_file($img);
            exit();

        }
       
header("Location: {$_SERVER['PHP_SELF']}}");
        die();

    }

    if (
$cbr=new comic_reader($cb)) {
       
$cbr->dir=$dir;
       
$urls = $cbr->list_files();

       
$slides_tmpl= new slide_show_html();
       
$slides_tmpl->file=$cb;
       
$slides_tmpl->dir=$dir;
       
$slides_tmpl->urls=$cbr->comic;
        echo
$slides_tmpl;
        exit();
    } else {

    }

} else {

   
$ini=parse_ini_file('comic.ini', TRUE);
   
$main="";
    foreach (
$ini as $i) {
       
$img=$i['img'][0];
       
$url=$_SERVER['PHP_SELF'] . "?" . base64_encode(str_replace($i['dir'], '', $i['file']));
       
$txt=$i['title'];

       
$main .= <<<EOF
<li><a href="$url" target="_blank">$txt</a><br /><img src="$img" /></li>
EOF;

    }

}




?><!DOCTYPE html>
<html>
<head>
    <title>cbr/cbz Comicbook viewer</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>
        * {box-sizing: border-box}

        body {
            font-family: "Lato", sans-serif;
            margin:0;
        }
        img {
            min-width: 100px;

            max-width: 300px;
            height: 500px;
            padding: 5px;
            margin: 5px;;
        }
        a {
            font-family: fantasy;
            font-size: larger;
            color: ghostwhite;
            background-color: darkred;
        }
        ul {
            list-style-type: none;

        }

        li {
            padding: 5px;
            margin: 5px;
            float: left;
            vertical-align: middle;
            text-align: center;
            border: solid;
            border-color: navy;
        }

    </style>
</head>
<body>
<ul>
<?php echo $main ?>
</ul>
<script>

</script>

</body>
</html>


Details

Package: ComicBookTools Author: Abu Khadeejah Karl Holz <binholz|a|hotmail|d|com> Licence: LICENCE

About Me

I'm Abu Khadeejah Karl Holz, I'm a StageHand by trade and coding is my hobby. I have diploma for Computer Systems Technologies from Seneca College in Toronto, this is where I learned the basics of UNIX, Linux, Shell Scripting, Perl, PHP, Windows, etc. I'm a father, so i have been busy taking care of my girl and not spending a lot of time coding php on my off time.

Comic Book Tools

this is a quick little tool to let you view your cbr files off of a webserver using PHP, like the built-in server. This project uses the rar pecl extention and it will need to be built by the user. Not all file versons are read by the pecl plugin, I have added a setup.php file that will create an ini file with all your cbz/cbr files, this is used for the front page page so you can select your comic from what was found. i have tried added conversion to png support, not all images seem to be viewable so far. the links that are generated are base64 encoded as a query string. you will need to increase the php memory usage for this class in your php.ini

File type viewing status

My class will deal with both rar and zip based comic books, class will test for rar first, then zip for all requests. 7-zip (cb7) is not supported, i didn't see a pecl extention or anything in the documentation about 7-zip. You can create a zip file arcive of selected images, like in MacOS Finder, then rename the extention to cbz.

<zipfile>.[zip|rar|cbr|cbz]
|_ File01.png
|_ File02.jpg
|_ File03.png

As you can see from above, this class can be used for more than just comics, take a look at the samples i made in the comic folder (check my github)

You Need the RAR PECL EXTENTION for cbr files

you will need this pecl extention installed on your system. i built it from source using the link bellow:

$ cd <src dir>
$ ./configure
$ make
$ make test
$ make install

I used the system version of PHP 7 in MacOS High Sieara and not MAMP (failed to build for me).

php.ini

Enable pecl extention in the /etc/php.ini

extension=rar.so

you should add the code bellow to your php.ini file, if my scripts setting doesn't work. Most images in cbr/cbz files are high resolution.

memory_limit = 2048M

use PHP built-in webserver

for this project, i'm just using the built in webserver for PHP since this is just a personal reader for comics that you can setup on a raspberry pi, pine64 or other SBC. take a look at the index.php and edit the $dir variable for your comic book directory.

$ cd <comic srv>
$ php -S localhost:8888 index.php
or
$ php -S <ip address|hostname>:8888 index.php

Support My Work

If you like any of the work I have done in the past, I'm welcome to any support you would like to provide via PayPal or EMT. I would like to focus on the projects with the most downloads, like the Excel2JSON, eKitab (code clean-up?), WebMap (upgrade) or others listed on PHP Classes website. My current computer is an MacMini 2010. I would like to get a new laptop (Mac perferablly). E-mail or make an issue on GitHub if you would like to ask questions or provide help. I like to keep things open source so we can have these tools availale and educational.


Screenshots (3)  
  • comic_view
  • commandline
  • index_page
  Files folder image Files (15)  
File Role Description
Files folder image.idea (6 files)
Accessible without login Plain text file comic.ini Data Auxiliary data
Plain text file ComicBookTools.class.php Class Class source
Accessible without login Plain text file index.php Example Example script
Accessible without login Plain text file LICENCE Lic. License text
Accessible without login Plain text file README.MD Doc. Documentation
Accessible without login Plain text file setup.php Example Example script

  Files folder image Files (15)  /  .idea  
File Role Description
  Accessible without login Plain text file comic_reader.iml Data Auxiliary data
  Accessible without login Plain text file misc.xml Data Auxiliary data
  Accessible without login Plain text file modules.xml Data Auxiliary data
  Accessible without login Plain text file php.xml Data Auxiliary data
  Accessible without login Plain text file vcs.xml Data Auxiliary data
  Accessible without login Plain text file workspace.xml Data Auxiliary data

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 80%
Total:111
This week:0
All time:9,625
This week:78Up