0

I'm wanting to utilise PHP's built-in imagejpeg and imagepng functions. I have a variable $type which defines the filetype jpeg or png.

I wanted to have one function call. Something like this:

image.$type($image, null, 100);

But that doesn't work. Any ideas?

1

1 Answer 1

1

It should works if you use the full function name in a var

$func = "image".$type;
$func($image,null,100);

Careful: imagepng use a quality between 0-9 (not 0 and 100)

for completeness: you should use an approach more solid, using a OOP method with Factory method pattern. However I don't know your situation and your code. So it's just a note.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.