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

Support for imagecropauto #158

Open
hempalex opened this issue Aug 10, 2020 · 6 comments
Open

Support for imagecropauto #158

hempalex opened this issue Aug 10, 2020 · 6 comments

Comments

@hempalex
Copy link

How can i use imagecropauto function for removing white/black/transparent borders before thumbnail creation.
I can't see any "prefilter" interfaces which I could use.

JamesHeinrich added a commit that referenced this issue Aug 10, 2020
@JamesHeinrich
Copy link
Owner

I have added a new parameter "ica" in 1766fa7
The value can be an integer 0-4 for the first 4 modes of imagecropauto, or 5|<threshold>|<hexcolor> where threshold is a value between 0-1 and hexcolor is a 6-char hexadecimal color string.

@hempalex
Copy link
Author

Thank you!

Is it possible to implement my own "pre-filters" without patching core of the library?
I'd like to implement more sophisticated auto cropping involving several calls to imagecropauto with different params depending on image content.

@JamesHeinrich
Copy link
Owner

I'm not opposed to that, I'm just trying to think of a good way to make that work. If you have any implementation suggestions I'm interested to hear them. I assume you'd be working in object mode rather than URL parameters?

One possibility to consider with the existing code is to use setSourceData instead of setSourceFilename, which would let you pre-process how you wish and then pass in the pre-processed image data. Or, of course, you could pre-process and write to disk and proceed with setSourceFilename, wouldn't be a big difference between the two approached (and both are not ideal, I understand that).

If you have suggestions for how to implement the possibility of passing in arbitrary pre-filtering code without causing security concerns I'm interested in your suggested approach.

@JamesHeinrich JamesHeinrich reopened this Aug 11, 2020
@hempalex
Copy link
Author

hempalex commented Aug 11, 2020

I can preprocess image myself, but it causes a lot of boilerplate code, like choosing function to read image from jpg/png/gif but the best code is not written code ))

In this particular case I'd suggest to use a similar to fltr[] approach, to allow to pass multiple cropping attempts. Now it's not possible to crop transparent border and white borders with the same code. But thumbnails are generated from many images, and it's not possible to know which cropping algo would be the best.

But in general I'd like to use some prefilters - like

$phpThumb->addPrefilter(function($gdImage) {   
    $cropped = imagecropauto($gdimage, IMG_CROP_TRANSPARENT);
    if ($cropped === false)  return $gdImage;

   $cropped =  imagecropauto($gdimage , IMG_CROP_THRESHOLD, 0.33, 0xFFFFFF);
    if ($cropped === false)  return $gdImage;

  return $cropped;
} );

and it could be the same with "postfilters", also you could recognise special keywords and implement built-in filters into pipeline.

But it can turn out to complete different library ))

@JamesHeinrich
Copy link
Owner

Would you be interested in writing said addPreFilter (and addPostFilter) changes for phpThumb.class and submitting a pull request?

@arturmamedov
Copy link
Contributor

Are this repo elligible for hacktoberfest?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants