GithubHelp home page GithubHelp logo

free-open-source / php-image-converter Goto Github PK

View Code? Open in Web Editor NEW
44.0 7.0 23.0 1.39 MB

PHP library to convert between gif, jpeg, png and webp image files

License: MIT License

PHP 100.00%
php7 php image image-processing image-converter image-conversion jpg png webp gif

php-image-converter's Introduction

PHP Image Converter

Version 1.2 beta

PHP library to convert between gif, jpeg, png and webp image files.

Usage

Syntax

echo \ImageConverter\convert(string $from , string $to , int $quality);

Example

<?php
include __DIR__ . '/src/php-image-converter.php';

$from = __DIR__ . '/my-image.png';
$to = __DIR__ . '/my-image.webp';

echo \ImageConverter\convert($from, $to);

Quality

The third argument is an optional $quality value. It will differ depending on your image format.

Format Default Min Max Description
gif null null null Quality value not supported
jpeg -1 0 100 Higher means better quality
png -1 0 9 Lower means better quality
webp 80 0 100 Higher means better quality

Notes

If you try to convert to a path that has not been created, it will try to create it automatically.

Requirements

  • PHP 7+
  • GD (active on almost every server by default)

Contributors

Contributing

Please see contributing for details.

Inspiration

Donate

Donate to DevoneraAB if you want.

License

MIT

php-image-converter's People

Contributors

jenstornell avatar peter279k avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-image-converter's Issues

Problem with WEBP images conversion with Travis CI

As title, I've found these image formats have some concerned problems.

  • According to the official reference, the imagebmp provided by GD extension only supports on php-7.2+.

This package requires php-7.2 version at least and can solve this problem.

That's why I do this on this PR #3.

  • According to the previous failed Travis CI build log, it looks like the php environment in Travis CI doesn't support the webp image.

I think we have to use the customized Docker image inside Travis CI if we need to test the webp image conversion.

Better shorter namespace?

The old syntax without namespace looks like this:

convertImage('./image.png', './image.webp', 5);

The new syntax will probably look something like this:

\Jens\ImageConverter\convertImage('./image.png', './image.webp', 5);

I don't really like the namespace, but I don't have a better suggestion at the moment.

Another idea

\ImageConverter\convert('./image.png', './image.webp', 5);

It's probably too generic, but I like the look of it better (I also changed the function name). It needs some more thought.

The reason I think it's important to get it right is that it's probably the only line of code most people will use. The rest is "hidden" in the class behind it.

Rethink about the string function call mapping

As title, please look at this code firstly.

It seems that we use the string function call mapping to dispatch the current imagecreatefrom and image function name.

But this approach is possible to cause some issues:

  • This should let us be hard to do debugging/reading work.
  • Don't make sure that this performance would be good.

I think we can consider using the switch......case to dispatch the current image functions.

Support quality percentage value for all formats where it's possible

Perhaps we should have the quality validation before passing the $quality to specific image manipulation functions?

#10 (comment)

@peter279k

The above gave me a new idea. Instead of having different types of quality ranges we could introduce a percentage value that works for every format that supports it.

Current way

This works now. Quality as integer.

echo \ImageConverter\convert('image.gif', 'image.jpg', 70);
echo \ImageConverter\convert('image.jpg', 'image.png', 5);

Additional way

To not need to keep track of the different format quality range, it could support a unified percentage range (which will be converted to the correct value). To make it possible, check if it's a string.

echo \ImageConverter\convert('image.gif', 'image.jpg', '70%');
echo \ImageConverter\convert('image.jpg', 'image.png', '60%');

Not yet sure if it's a good idea yet, but I'll throw it out here before I forget about it.

Don't have enough time

@peter279k I have noticed that I don't have that much time for this project. Also I think that most of what it should contain already works well.

Therefor I wonder if you would like to take it over, meaning that I send a request to move the repository to you?

I can still send issues and pull requests when needed. You will then have more freedom to commit.

Revert converImage function helper

As title, It's related to PR #3.

I try removing the convertImage function and using the ImageConverter class directly.

The convertImage is unnecessary because we can use the ImageConverter class directly.

Once the PR #3 is approved, I can do this to update the example.

Using GitHub actions to replace Travis CI build

It's related to issue #4.

At this moment, the PHP GD extension with WEBP extension is not worked well during Travis CI build.

IMHO, we should consider using the GitHub actions to replace the Travis CI build.

And I think this issue will be resolved, too.

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.