recreate project

This commit is contained in:
root
2026-02-10 22:11:06 -05:00
commit 663c0cdbda
10149 changed files with 1379710 additions and 0 deletions
File diff suppressed because it is too large Load Diff
+20
View File
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SPHINXPROJ = gfx-php
SOURCEDIR = .
BUILDDIR = _build
# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
.PHONY: help Makefile
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
View File
@@ -0,0 +1,4 @@
{%- extends "sphinx_rtd_theme/breadcrumbs.html" %}
{% block breadcrumbs_aside %}
{% endblock %}
+173
View File
@@ -0,0 +1,173 @@
# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
#
# This file does only contain a selection of the most common options. For a
# full list see the documentation:
# http://www.sphinx-doc.org/en/master/config
# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
# -- Project information -----------------------------------------------------
project = 'gfx-php'
copyright = '2018, Michael Billington'
author = 'Michael Billington'
# The short X.Y version
version = ''
# The full version, including alpha/beta/rc tags
release = ''
# -- General configuration ---------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
#
# needs_sphinx = '1.0'
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
"sphinxcontrib.phpdomain"
]
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
# The master toctree document.
master_doc = 'index'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path .
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# -- Options for HTML output -------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#
# html_theme_options = {}
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
#
# The default sidebars (for documents that don't match any pattern) are
# defined by theme itself. Builtin themes are using these templates by
# default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
# 'searchbox.html']``.
#
# html_sidebars = {}
# -- Options for HTMLHelp output ---------------------------------------------
# Output file base name for HTML help builder.
htmlhelp_basename = 'gfx-phpdoc'
# -- Options for LaTeX output ------------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',
# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'gfx-php.tex', 'gfx-php Documentation',
'Michael Billington', 'manual'),
]
# -- Options for manual page output ------------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'gfx-php', 'gfx-php Documentation',
[author], 1)
]
# -- Options for Texinfo output ----------------------------------------------
# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'gfx-php', 'gfx-php Documentation',
author, 'gfx-php', 'One line description of project.',
'Miscellaneous'),
]
# PHP Syntax
from sphinx.highlighting import lexers
from pygments.lexers.web import PhpLexer
lexers["php"] = PhpLexer(startinline=True, linenos=1)
lexers["php-annotations"] = PhpLexer(startinline=True, linenos=1)
# Set domain
primary_domain = "php"
# Regenerate API docs via doxygen + doxyphp2sphinx
import subprocess, os
read_the_docs_build = os.environ.get('READTHEDOCS', None) == 'True'
if read_the_docs_build:
subprocess.call(['doxygen', 'Doxyfile'])
subprocess.call(['doxyphp2sphinx', 'Mike42::GfxPhp'])
+68
View File
@@ -0,0 +1,68 @@
The pure PHP graphics library
=====================================
This library implements input, output and processing of raster images in pure
PHP, so that image processing PHP extensions are not required.
This allows developers to eliminate some portability issues from their applications.
The basic usage is like this:
.. code-block:: php
<?php
use Mike42\GfxPhp\Image;
$img = Image::fromFile("colorwheel256.png");
$img -> write("test.gif");
Features
--------
- Format support includes PNG, GIF, BMP and the Netpbm formats.
- Support for scaling, cropping, format conversion and colorspace transformations.
- Pure PHP: This library does not require Gd, ImageMagick or GraphicsMagick extensions.
Installation
------------
Install gfx-php by running:
.. code-block:: bash
composer install mike42/gfx-php
Contribute
----------
- Issue Tracker: https://github.com/mike42/gfx-php/issues
- Source Code: https://github.com/mike42/gfx-php
Navigation
==========
.. toctree::
:maxdepth: 1
:caption: User Documentation
user/formats.rst
user/imagetypes.rst
user/operations.rst
.. toctree::
:maxdepth: 1
:caption: Project Information
project/license.rst
project/contributing.rst
.. toctree::
:maxdepth: 2
:caption: API Documentation
Classes <api.rst>
Indices and tables
==================
* :ref:`genindex`
* :ref:`search`
+117
View File
@@ -0,0 +1,117 @@
Contributor guide
=================
This project is open source, and is built on a voluntary basis by developers like you. You can help to improve it by contributing code & documentation to the repository, or by interacting with other developers and users on the issue tracker.
Where to ask a question
^^^^^^^^^^^^^^^^^^^^^^^
If you need to seek clarification, then you are welcome to post questions about the library to the `gfx-php issue tracker`_. They will be tagged ``question``, and closed once there is an answer.
If your question is incomplete or not specific to this project, then it will be tagged ``invalid`` and closed with a short explanation. We do this to keep the issue tracker focussed, on-topic and actionable by project contributors.
The StackOverflow help page `How do I ask a good question?`_ contains advice about writing complete questions.
.. _`How do I ask a good question?`: https://stackoverflow.com/help/how-to-ask
How to report a bug
^^^^^^^^^^^^^^^^^^^
We track bugs as GitHub issues. If something does not work as documented, then you are welcome to make a bug report on the `gfx-php issue tracker`_
When posting a bug:
- Check for open issues first. If the same issue has already been reported, then you should post any additional information to the existing thread.
- Describe what you are trying to do, and how the actual behaviour of the library differs from what you expected.
- Include a self-contained code snippet that demonstrates the issue, as PHP code formatted in a `code block`_
- Try to use images from the repository to demonstrate the problem. If you need to use a specific example image, then attach it to the issue in a ``.zip`` file.
Bug reports will stay open as long as they are actionable. Generally, this means that they can be replicated on the current stable release, and there is some expectation that the issue is solvable.
The title and tags on your bug may be edited so that it can be distinguished from other bugs.
.. _`code block`: https://help.github.com/articles/creating-and-highlighting-code-blocks/
.. _`gfx-php issue tracker`: https://github.com/mike42/gfx-php/issues
Feature requests
^^^^^^^^^^^^^^^^
You can also make suggestions for new features on the `gfx-php issue tracker`_. These are tagged ``enhancement``.
Please keep the scope and resources of the project in mind when making suggestions.
Development process
^^^^^^^^^^^^^^^^^^^
The project is hosted online on the services below:
:Code:
https://github.com/mike42/gfx-php
:Continuous integration:
https://travis-ci.org/mike42/gfx-php
:Code coverage reporting:
https://coveralls.io/github/mike42/gfx-php
:Documentation:
https://gfx-php.readthedocs.io/
:Package manager:
https://packagist.org/packages/mike42/gfx-php
For a change to be accepted, it will first need to meet some basic technical criteria, such as passing existing unit tests, a style check, and not breaking any of the examples.
Secondly, it will need to pass a human review, to confirm that it improves the overall product. You are encouraged to submit changes which address one open issue, so that this review can be as constructive as possible.
Commands to use locally
-----------------------
To make code changes, fork the repository on GitHub, and set up
your local copy with composer.
.. code-block:: bash
composer install
To run unit tests, execute:
.. code-block:: bash
php vendor/bin/phpunit --coverage-text
To test all examples:
.. code-block:: bash
mkdir -p tmp && (cd tmp && find ../example -name '*.php' -print0 | xargs -n 1 -0 sh -c 'echo $0; php $0 || exit 255')
To run a style check and fix formatting issues:
.. code-block:: bash
php vendor/bin/phpcs --standard=psr2 src/ -n
php vendor/bin/phpcbf --standard=psr2 src/ -n
Submitting changes
------------------
Changes should be submitted as a GitHub pull request to the ``master`` branch.
Licensing considerations
------------------------
You are not required to assign copyright for contributions to this project, but
you do need ensure that your changes are suitable for release under the project's
`copyleft` license.
If you hold the copyright to the submitted code, then indicate this in your pull request.
If you are thinking of including code which you do not hold the copyright to,
please post relevant details to the issue tracker first. Only works which are
licensed under an LGPL-2.1-compatible license may be combined with `gfx-php` code.
Release process
---------------
Git tags are automatically reflected as releases in packagist.
Release numbers approximately follow semantic versioning, and do not follow a particular schedule.
Updates are not typically made to old releases.
+4
View File
@@ -0,0 +1,4 @@
License
=======
.. literalinclude:: ../../LICENSE
+4
View File
@@ -0,0 +1,4 @@
Sphinx==1.7.4
sphinx-rtd-theme==0.3.0
sphinxcontrib-phpdomain==0.4.1
doxyphp2sphinx>=1.0.1
+159
View File
@@ -0,0 +1,159 @@
File formats
============
.. contents::
:local:
Input formats
-------------
Files are read from a file or URL by using the :meth:`Image::fromFile()` function:
.. code-block:: php
use Mike42\GfxPhp\Image;
$tux = Image::fromFile("tux.png")
If the your image is not being read from a file, then :meth:`Image::fromBlob()` can load it from a binary string:
.. code-block:: php
use Mike42\GfxPhp\Image;
$tuxStr = "...";
$tux = Image::fromBlob($tuxStr, "tux.png");
In either case, the input format is determined using the file's `magic number`_.
.. _magic number: https://en.wikipedia.org/wiki/Magic_number_(programming)
PNG
^^^
The PNG codec is used where the input has the ``png`` file extension.
All valid PNG files can be read, including:
- RGB or RGBA images
- Indexed images
- Monochrome images, from 1 to 16 bits per pixel
- Interlaced images
This library currently has limited support for transparency, and will discard any alpha channel from a PNG file when it is loaded.
GIF
^^^
The GIF codec is used where the input has the ``gif`` file extension. Any well-formed GIF file can be read, but there are some limitations:
- If a GIF file contains multiple images, then only the first one will be loaded
- If a transparent color is present, then this will be mixed to white
A GIF image will always be loaded into an instance of :class:`IndexedRasterImage`, which makes palette information available.
BMP
^^^
The BMP codec is used where the input has the ``bmp`` or ``dib`` file extensions. Most uncompressed or run-length encoded bitmap files can be read by this library.
The returned object will be an instance of instance of :class:`IndexedRasterImage` if the color depth is 8 or lower.
24-bit, 16-bit and 32-bit bitmap images are also supported, and will be loaded into an instance of :class:`RgbRasterImage`. If an alpha channel is used, then it will be mixed to white.
Netpbm Formats
^^^^^^^^^^^^^^
The Netpbm formats are a series of uncompressed bitmap formats, which can represent most types of image. These formats can be read by ``gfx-php``:
:PNM: This is a file extension only. Files carrying ``.pnm`` extension can carry any of the below formats.
:PPM: This is a color raster format. A PPM file is identified by the P6 magic number, and will be loaded into an instance of :class:`RgbRasterImage`.
:PGM: This is a monochrome raster format. A PGM file is identified by the P5 magic number, and will be loaded instance of :class:`GrayscaleRasterImage`.
:PBM: This is a 1-bit bitmap format. A PBM file is identified by the P4 header, and loaded into an instance of :class:`BlackAndWhiteRasterImage`.
Each of these formats has both a binary and text encoding. ``gfx-php`` only supports the binary encodings at this stage.
WBMP
^^^
The WBMP codec is used where the input has the ``wbmp`` file extension. A WBMP image will always be loaded into a :class:`BlackAndWhiteRasterImage` object.
Output formats
--------------
When you write a :class:`RasterImage` to a file, you need to specify a filename. The extension on this file is used to determine the desired output format.
There is currently no mechanism to write a file directly to a string.
PNG
^^^
The PNG format is selected by using the ``png`` file extension when you call :func:`RasterImage::write()`.
.. code-block:: php
$tux -> write("tux.png");
This library will currently output PNG files as RGB data. If you write to PNG from an instance of :class:`RgbRasterImage`, then no conversion has to be done, so the output is significantly faster.
GIF
^^^
The GIF format is selected by using the ``gif`` file extension.
.. code-block:: php
$tux -> write("tux.gif");
This format is limited to using a 256-color palette.
- If your image is not an `IndexedRasterImage`, then it is indexed when you write.
- If the image uses more than 256 colors, then it will be converted to an 8-bit RGB representation (3 bits red, 3 bits green, 2 bits blue), which introduces some distortions.
When you are creating GIF images, then you can avoid these conversions by using a :class:`IndexedRasterImage` with a palette of fewer than 256 colors.
There is no encoder for multi-image GIF files at this stage.
BMP
^^^
The BMP format is selected by using the ``bmp`` file extension.
.. code-block:: php
$tux -> write("tux.bmp");
This library will currently output BMP files using an uncompressed 24-bit RGB representation of the image.
WBMP
^^^
The WBMP format is selected by using the ``wbmp`` file extension.
.. code-block:: php
$tux -> write("tux.wbmp");
The image will be converted to a 1-bit monochrome representation, which is the only type of image supported by WBMP.
Netpbm Formats
^^^^^^^^^^^^^^
The Netpbm formats can be used for output. Each format is identified by their respective file extension:
.. code-block:: php
$tux -> write("tux.ppm");
$tux -> write("tux.pgm";
$tux -> write("tux.pbm");
Since each of these formats has a different raster data representation, you should be aware that
:PPM: For this output format, the file is converted to a :class:`RgbRasterImage` and typically written with a 24 bit color depth. In some cases, a 48 bit color depth will be used.
:PGM: The file is converted to a :class:`GrayscaleRasterImage` and written with a depth of 8 or 16 bits per pixel.
:PPM: The file is converted to a :class:`BlackAndWhiteRasterImage` and written with 1 bit per pixel.
If you want to avoid these conversions, then you should use the ``pnm`` extension to write your files. Since files with this extension can hold any of the above formats, the output encoder will avoid converting the raster data where possible.
.. code-block:: php
$tux -> write("tux.pnm");
+61
View File
@@ -0,0 +1,61 @@
Image types
===========
Every raster image in ``gfx-php`` implements the :class:`RasterImage` interface.
There are several classes that implement this interface, which handle different representations of
the image data.
:class:`RgbRasterImage`
Holds RGB data.
:class:`GrayscaleRasterImage`
Holds monochrome data.
:class:`BlackAndWhiteRasterImage`
Holds 1-bit raster data.
:class:`IndexedRasterImage`
Holds an image and associated palette.
Creating an image
^^^^^^^^^^^^^^^^^
Each of these classes has a static method which can be used to create an image of that type.
These only require a ``width`` and ``height``.
.. code-block:: php
use Mike42\GfxPhp\BlackAndWhiteRasterImage;
$image = BlackAndWhiteRasterImage::create(50, 100);
Converting between image types
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
You can convert between image types. This is similar to performing a `color-space conversion` in an image editor.
.. code-block:: php
use Mike42\GfxPhp\Image;
$image = Image::load("tux.ppm");
$image -> toBlackAndWhite();
The methods to use are:
- :meth:`RasterImage::toBlackAndWhite()`
- :meth:`RasterImage::toGrayscale()`
- :meth:`RasterImage::toIndexed()`
- :meth:`RasterImage::toRgb()`
Each of these returns an image of the requested type. They work by instantiating a new image, then copying across the data as accurately as possible. As a result, the original image is unmodified.
Implicit conversions
^^^^^^^^^^^^^^^^^^^^
Some file formats only accept specific types of raster data, so the :meth:`RasterImage::write()` method will need to convert it. For example, this ``.pbm`` will be limited to 2 colors, which is achieved by using :meth:`RasterImage:toBlackAndWhite` in the background:
.. code-block:: php
use Mike42\GfxPhp\Image;
$wheel = Image::load("colorwheel.ppm");
$wheel -> write("wheel.pbm");
Since converting the color space creates a new image, the image stored in ``$wheel`` is unmodified.
+12
View File
@@ -0,0 +1,12 @@
Image operations
================
You can use this library to perform basic raster operations, such as:
- Crop
- Scale / resize
- Color-space conversions
See the ``example/`` sub-folder `on GitHub`_ for usage.
.. _`on GitHub`: https://github.com/mike42/gfx-php/tree/master/example