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

[5.6] Add JPEG support to FileFactory::image() #24853

Merged
merged 1 commit into from
Jul 17, 2018

Conversation

SimonStaudenmeir
Copy link
Contributor

Currently, when generating dummy images for testing, FileFactory::image() always creates a PNG:

UploadedFile::fake()->image('avatar.png') // Creates PNG file.
UploadedFile::fake()->image('avatar.jpg') // Also creates PNG file.

This PR checks the file extension and creates JPEG images when the filename ends with .jpeg or .jpg.

The tests use getimagesize() instead of $image->getMimeType(). getMimeType() derives the mime type from the filename, while getimagesize() examines the actual file.

@@ -28,7 +30,9 @@ public function create($name, $kilobytes = 0)
*/
public function image($name, $width = 10, $height = 10)
{
return new File($name, $this->generateImage($width, $height));
$type = Str::endsWith($name, ['.jpg', '.jpeg']) ? 'jpeg' : 'png';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use strtolower($name) because in some cases image.JPG might also come.

@taylorotwell taylorotwell merged commit a451a2b into laravel:5.6 Jul 17, 2018
@SimonStaudenmeir SimonStaudenmeir deleted the fake-image-jpg branch July 17, 2018 14:08
@crynobone
Copy link
Member

screen shot 2018-07-18 at 6 45 15 pm

This could cause a tests failure if your testing environment is not configure gd with jpeg support. See https://stackoverflow.com/questions/19028793/fatal-error-call-to-undefined-function-imagejpeg-on-heroku-php-fix/34764738#34764738

@pierrocknroll
Copy link

Same error here... :(

@mvanduijker
Copy link

If you have failing tests, test with a png image by making sure it has .png file extension.

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

Successfully merging this pull request may close these issues.

6 participants