Comments (8)
One idea that comes to mind is this...
$override = false; // Default is true
echo \ImageConverter\convert($from , $to , $quality, $override);
...but because both $quality
and $override
are optional I don't really like it. What if I don't want to specify the quality argument?
@peter279k If the file is saved successfully, I think it should return true
no matter if an image already exists or not. That's because true
means that the operation was successful.
If the $override
is false, it should not override an already existing file and because that operation will fail it should return false
. On error somewhere throw an exception.
from php-image-converter.
I'm just throwing in another concept in here.
echo \ImageConverter\convert($from, $to);
echo \ImageConverter\convert($from, $to , $quality = 80);
echo \ImageConverter\convert($from, $to , $args = ['quality' => 80, 'override' => 'false']);
With this concept it works just as now, BUT if the third and only optional argument is an array, treat it as an array with options.
from php-image-converter.
@peter279k I agree.
A day has gone and now I get confused about the override
return.
If override
is false
and a file already exists, it should not override the file, but is it successful or not? It can be successful, because it did not convert the image file BUT it can be successful because the expected behaviour can be that it should just skip the file if it already exists and then move on.
Maybe I'm overdoing it but this is another idea:
echo \ImageConverter\convert($from, $to , $args = [
'override' => false,
'debug' => true
]);
In case of debug
is true
it can return an array like below:
[
'success' => true,
'file_overwritten' => true,
// from path
// to path
// from format
// to format
// from filesize
// to filesize
// filesize diff
]
from php-image-converter.
Before adding a file_exists
in there, test the code without it and see what happends. Maybe exif_imagetype
will take care of it?
from php-image-converter.
Well, we have the two options to check whether the targeted file is existed.
- Using
file_exists
before saving/overriding the image file. - Using the
exif_imagetype
to detect the image file type before saving/overriding image file.
I think these two approaches can choose one and I also notice that we have to detect the targeted image file is saved/override.
If saving the image file, what will we do for the behavior? Return the message string?
If overriding the image file, what will we do for the behavior? Return the message string?
from php-image-converter.
Hi @jenstornell, thank you for your recommendation.
It looks good. The method returns true
when the image file is saved. Otherwise, it returns false
when the file is override.
About the $quality
argument, it's normal that the optional argument will be the last in specific method.
That is, consider following code snippets:
.......
function this_function($required, $required2, $option = 'option1', $option2 = 'option2')
......
You can also look at the native PHP function reference and you will know what I talk about :).
If we want to pass one of optional argument, perhaps we have to use the func_get_args and func_num_args to parse function argument lists to detect whether the $quality
is defined.
We can check the second argument is integer or bool type.
If it's integer
type, it defines the $quality
variable.
Otherwise, the $quality
variable is not defined.
from php-image-converter.
@peter279k Interesting ideas. I've done a type check in previous projects and it works but it can be messy, especially with three or four optional arguments. It needs to ask itself.
- Are there two optional arguments?
- Are there one optional argument?
- Which one argument should I use?
My suggestion is that we don't stress it with this one until there is a really clear and perfect way to solve it. Else we may end up changing the behaviour later and rewrite it.
from php-image-converter.
Hi @jenstornell, thank you for your reply.
I think this approach you mention is better than mine.
It's good for us to let this additional arg
in convert
function be array 👍 .
from php-image-converter.
Related Issues (17)
- Better tests HOT 2
- Replace 5 with $quality - Else quality is always 5 HOT 7
- imagegif function doesn't have quality argument HOT 3
- Support quality percentage value for all formats where it's possible HOT 4
- Quality validation HOT 1
- Don't have enough time HOT 10
- Method to convert to gd object and return that HOT 3
- Issue templates HOT 2
- Pull request template
- Using GitHub actions to replace Travis CI build HOT 1
- Problem with WEBP images conversion with Travis CI HOT 4
- Revert converImage function helper HOT 3
- Better shorter namespace? HOT 2
- Rethink about the string function call mapping HOT 2
- Docs needs to be updated when things are in the right place HOT 1
- Reimplement BMP HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-image-converter.