Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3.0.0 #4

Draft
wants to merge 29 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e8b2673
refactor: remove binaries from version control
karkowg Nov 8, 2024
004155d
chore: bump mupdf to 1.24.10
karkowg Nov 8, 2024
fd446d7
chore: tidy up composer.json
karkowg Nov 8, 2024
229d3c8
refactor: update namespace
karkowg Nov 8, 2024
ecf83ea
docs: refresh README
karkowg Nov 8, 2024
8a58bed
chore: refactor tests workflow to build mutool 1/19289012
karkowg Nov 8, 2024
7ebae91
chore: refactor tests workflow to build mutool 2/19289012
karkowg Nov 8, 2024
88a15ae
chore: refactor tests workflow to build mutool 3/19289012
karkowg Nov 8, 2024
816f078
chore: refactor tests workflow to build mutool 4/19289012 (forget win…
karkowg Nov 8, 2024
76b40f5
chore: attempt 1/1231823 trying to build binary as release artifacts
karkowg Nov 8, 2024
fda949c
chore: attempt 2/1231823 trying to build binary as release artifacts
karkowg Nov 8, 2024
a6ead33
chore: attempt 3/1231823 trying to build binary as release artifacts
karkowg Nov 10, 2024
00d89d9
chore: attempt 7/1231823 trying to build binary as release artifacts
karkowg Nov 10, 2024
1598193
chore: attempt 8/1231823 trying to build binary as release artifacts
karkowg Nov 10, 2024
86c6dea
chore: attempt 9/1231823 trying to build binary as release artifacts
karkowg Nov 10, 2024
9ff0058
chore: attempt 10/1231823 trying to build binary as release artifacts
karkowg Nov 10, 2024
4babb46
chore: attempt 11/1231823 trying to build binary as release artifacts
karkowg Nov 11, 2024
82579dc
chore: attempt 12/1231823 trying to build binary as release artifacts
karkowg Nov 11, 2024
03cecf4
chore: attempt 13/1231823 trying to build binary as release artifacts
karkowg Nov 11, 2024
687ea37
chore: attempt 14/1231823 trying to build binary as release artifacts
karkowg Nov 11, 2024
449c0fb
chore: attempt 15/1231823 trying to build binary as release artifacts
karkowg Nov 11, 2024
1cd3319
chore: attempt 16/1231823 trying to build binary as release artifacts
karkowg Nov 11, 2024
15cc260
chore: attempt 17/1231823 trying to build binary as release artifacts
karkowg Nov 11, 2024
c65f0c0
chore: attempt 18/1231823 trying to build binary as release artifacts
karkowg Nov 11, 2024
cbfd44c
chore: attempt 19/1231823 trying to build binary as release artifacts
karkowg Nov 11, 2024
1e94a4f
chore: attempt 20/1231823 trying to build binary as release artifacts
karkowg Nov 11, 2024
e1da244
chore: attempt 21/1231823 trying to build binary as release artifacts
karkowg Nov 11, 2024
62767da
chore: attempt 22/1231823 trying to build binary as release artifacts
karkowg Nov 11, 2024
df57aa5
chore: attempt 23/1231823 trying to build binary as release artifacts
karkowg Nov 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
name: Release

on:
push:
tags:
- "v*"

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [ ubuntu-latest, macos-latest ]
arch: [ x86_64, arm64 ]
exclude:
- os: macos-latest
arch: x86_64

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up permissions to execute build script for Linux/macOS
if: ${{ matrix.os != 'windows-latest' }}
run: chmod +x build-mupdf.sh

- name: Install cross-compiler for arm64 on Ubuntu
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu

- name: Install XQuartz
if: ${{ matrix.os == 'macos-latest' }}
run: |
echo "export HOMEBREW_NO_AUTO_UPDATE=1" >> $GITHUB_ENV
brew install --cask xquartz

- name: Build mutool for ${{ matrix.os }} ${{ matrix.arch }}
shell: bash
run: |
target_os=${{ matrix.os == 'ubuntu-latest' && 'linux' || 'darwin' }}
target_arch=${{ matrix.arch }}

OS=$target_os ARCH=$target_arch ./build-mupdf.sh

- name: Upload binary artifact
uses: actions/upload-artifact@v4
with:
name: mutool_${{ matrix.os == 'ubuntu-latest' && 'linux' || 'darwin' }}_${{ matrix.arch }}
# path: bin/mutool_${{ matrix.os }}*
path: bin/mutool*

release:
needs: build
runs-on: ubuntu-latest
steps:
- name: Download mutool binaries
uses: actions/download-artifact@v4
with:
path: bin/
pattern: mutool_*

- name: Create release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: true
prerelease: false

- name: Upload Linux binary (x86_64) to Release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: bin/mutool_linux_x86_64
asset_name: mutool_linux_x86_64
asset_content_type: application/octet-stream

- name: Upload Linux binary (arm64) to Release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: bin/mutool_linux_arm64
asset_name: mutool_linux_arm64
asset_content_type: application/octet-stream

- name: Upload macOS binary (x86_64) to Release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: bin/mutool_darwin_x86_64
asset_name: mutool_darwin_x86_64
asset_content_type: application/octet-stream

- name: Upload macOS binary (arm64) to Release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: bin/mutool_darwin_arm64
asset_name: mutool_darwin_arm64
asset_content_type: application/octet-stream
23 changes: 15 additions & 8 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Tests

on: [ 'push', 'pull_request' ]
# on: [ 'push', 'pull_request' ]
on:
push:
branches:
- "master"

jobs:
ci:
Expand All @@ -15,12 +19,11 @@ jobs:
name: Tests P${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }}

steps:

- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Cache dependencies
uses: actions/cache@v1
uses: actions/cache@v4
with:
path: ~/.composer/cache/files
key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
Expand All @@ -35,9 +38,13 @@ jobs:
- name: Install Composer dependencies
run: composer update --${{ matrix.dependency-version }} --no-interaction --prefer-dist

- name: Replace mutool binary for macos
if: ${{ matrix.os == 'macos-latest' }}
run: mv ./bin/mutool-macos ./bin/mutool
- name: Set up permissions to execute build script for Linux/macOS
if: ${{ matrix.os != 'windows-latest' }}
run: chmod +x build-mupdf.sh

- name: Build mutool
shell: bash
run: ./build-mupdf.sh

- name: Unit Tests
- name: Unit tests
run: php ./vendor/bin/pest
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ vendor
phpcs.xml
phpunit.xml
.phpunit.result.cache
.idea
.vscode
.phpactor.json
39 changes: 26 additions & 13 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
# Changelog

All notable changes to `php-mupdf` will be documented in this file.

Updates should follow the [Keep a CHANGELOG](https://keepachangelog.com/) principles.

## NEXT - YYYY-MM-DD
## [Unreleased]

## [3.0.0] - 2024-11-08
> v3.0.0 is a major release with breaking changes.
### Added
- Nothing

### Deprecated
- Nothing
- Workflow for building `mutool` binary for different platforms and packaging it as a release asset
### Removed
- `mutool` binary is now available as a release asset instead of being commited to repository

### Fixed
- Nothing
## [2.0.1] - 2024-05-22
### Added
- Support for PHP 8.2

## [2.0.0] - 2022-08-11
### Removed
- Nothing
- Support for PHP 7.4

## [1.1.0] - 2022-07-22
### Added
- Support for png format

### Security
- Nothing
## [1.0.0] - 2022-07-21
> Initial release
### Added
- Convert PDF to jpg

[unreleased]: https://github.com/dotgksh/php-mupdf/compare/v1.0.0...HEAD
[1.0.0]: https://github.com/dotgksh/php-mupdf/releases/tag/v1.0.0
[1.1.0]: https://github.com/dotgksh/php-mupdf/releases/tag/v1.1.0
[2.0.0]: https://github.com/dotgksh/php-mupdf/releases/tag/v2.0.0
[2.0.1]: https://github.com/dotgksh/php-mupdf/releases/tag/v2.0.1
[3.0.0]: https://github.com/dotgksh/php-mupdf/releases/tag/v3.0.0
46 changes: 10 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,21 @@ Minimal PDF to image converter using [MuPDF](https://mupdf.com/docs/mutool.html)
[![Total Downloads](https://img.shields.io/packagist/dt/karkowg/php-mupdf.svg)](https://packagist.org/packages/karkowg/php-mupdf)

## Install

Via Composer

``` bash
$ composer require karkowg/php-mupdf
```

## Usage

### Convert all the pages to jpg

``` php
$pdf = new Karkow\MuPdf\Pdf('path/to/pdf/file');
$pdf = new Gksh\MuPdf\Pdf('path/to/pdf/file');

$pdf->saveAllPagesAsImages('./images/', 'page-');
```

### Convert a single page to png

``` php
$pdf = new Karkow\MuPdf\Pdf('path/to/pdf/file');
$pdf = new Gksh\MuPdf\Pdf('path/to/pdf/file');

$pdf
->setPage(2)
Expand All @@ -42,50 +36,30 @@ $pdf
Please refer to `tests/PdfTest.php` for other use cases.

## [mutool](https://mupdf.com/releases/index.html)

A compiled binary (v1.20.0) is available at `bin/mutool`. If for any reason you want/need to use your own installation, you can do so by passing its path as a 2nd argument to the constructor.
A build script will compile `mutool` and make it available under `bin/mutool`. If for any reason you want/need to use your own installation, you can do so by passing its path as a 2nd argument to the constructor.

``` php
$pdf = new Karkow\MuPdf\Pdf('path/to/pdf/file', 'path/to/mutool');
$pdf = new Gksh\MuPdf\Pdf('path/to/pdf/file', 'path/to/mutool');
```

## Change log

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

## Testing

``` bash
$ ./build-mupdf.sh
$ composer test
```

## Contributing
## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) and [CODE_OF_CONDUCT](CODE_OF_CONDUCT.md) for details.

## Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

## Credits

- [Gustavo Karkow][link-author]
- [All Contributors][link-contributors]
- [Gustavo Karkow](https://github.com/karkowg)
- [All Contributors](../../contributors)

## License

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

[ico-version]: https://img.shields.io/packagist/v/karkowg/php-mupdf.svg?style=flat-square
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
[ico-travis]: https://img.shields.io/travis/karkowg/php-mupdf/master.svg?style=flat-square
[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/karkowg/php-mupdf.svg?style=flat-square
[ico-code-quality]: https://img.shields.io/scrutinizer/g/karkowg/php-mupdf.svg?style=flat-square
[ico-downloads]: https://img.shields.io/packagist/dt/karkowg/php-mupdf.svg?style=flat-square

[link-packagist]: https://packagist.org/packages/karkowg/php-mupdf
[link-travis]: https://travis-ci.org/karkowg/php-mupdf
[link-scrutinizer]: https://scrutinizer-ci.com/g/karkowg/php-mupdf/code-structure
[link-code-quality]: https://scrutinizer-ci.com/g/karkowg/php-mupdf
[link-downloads]: https://packagist.org/packages/karkowg/php-mupdf
[link-author]: https://github.com/karkowg
2 changes: 0 additions & 2 deletions bin/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
*
!mutool
!mutool-macos
Binary file removed bin/mutool
Binary file not shown.
Binary file removed bin/mutool-macos
Binary file not shown.
48 changes: 41 additions & 7 deletions build-mupdf.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,46 @@
#!/usr/bin/env bash

rm -f ./bin/mutool
VERSION=1.24.10

rm -rf ./build
mkdir build
cd build
curl "https://mupdf.com/downloads/archive/mupdf-1.20.0-source.tar.gz" -o "mupdf.tar.gz"
mkdir -p build
mkdir -p bin

cd build || exit
curl "https://mupdf.com/downloads/archive/mupdf-$VERSION-source.tar.gz" -o "mupdf.tar.gz"
tar -xf mupdf.tar.gz
cd mupdf-1.20.0-source
make HAVE_X11=no HAVE_GLUT=no prefix=../. install
cd mupdf-$VERSION-source || exit
if [[ "$OS" == "linux" ]]; then
if [[ "$ARCH" == "x86_64" ]]; then
export CC="gcc"
export XCFLAGS="-m64"
elif [[ "$ARCH" == "arm64" ]]; then
export CC="aarch64-linux-gnu-gcc"
export CXX="aarch64-linux-gnu-g++"
export XCFLAGS="-march=armv8-a"
fi
make HAVE_X11=no HAVE_GLUT=no prefix=../. install
else
if [[ "$ARCH" == "x86_64" ]]; then
export CC="clang"
export CXX="clang++"
export XCFLAGS="-arch x86_64"
export XLDFLAGS="-L/opt/X11/lib -lX11 -framework OpenGL"
export XCXXFLAGS="-v"
elif [[ "$ARCH" == "arm64" ]]; then
export CC="gcc-12"
export CXX="g++-12"
export XCFLAGS="-arch arm64 -I/opt/X11/include"
export XLDFLAGS="-L/opt/X11/lib -lX11 -framework OpenGL"
export XCXXFLAGS="-v"
fi
which xterm
ps aux | grep XQuartz
make prefix=../. install
fi

cd ..
ls -la
cp ./bin/mutool ../bin/mutool
cd ..
cp bin/mutool ../bin/mutool
ls -la bin
Loading
Loading