Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

JPEG Only Supported

Uploading PNG or GIF files appears to strip the transparency (the image is saved as JPG). Could we get transparency supported added?

Comments

  • Fixed it myself. Changed "jpg" in GenerateTargetName call and SaveImageAs call to "png".

  • agcyphersagcyphers
    edited January 2015

    Here's a more in-depth fix (detect image type). Beginning at line 446, through 476.

            $imageType = end(explode('.', $_FILES[$UploadFieldName]['name']));
            $suppTypes = array('jpg', 'png', 'gif', 'ico', 'jpeg');
            if( in_array($imageType, $suppTypes) === false ) {
                $imageType = 'jpg';
            }
    
            // Generate the target image name.
            $CurrentYear = date('Y');
            $CurrentMonth = date('m');
            $UploadPath = PATH_UPLOADS . '/articles/' . $CurrentYear . '/' . $CurrentMonth;
            $TargetImage = $UploadImage->GenerateTargetName($UploadPath, $imageType, false);
            $Basename = pathinfo($TargetImage, PATHINFO_BASENAME);
            $UploadsSubdir = '/articles/' . $CurrentYear . '/' . $CurrentMonth;
    
            if($isThumbnail) {
                $SaveWidth = C('Articles.Articles.ThumbnailWidth', 260);
                $SaveHeight = C('Articles.Articles.ThumbnailHeight', 146);
            } else {
                $SaveWidth = null;
                $SaveHeight = null;
            }
    
            // Save the uploaded image.
            $Props = $UploadImage->SaveImageAs(
                $TmpFileName,
                $UploadsSubdir . '/' . $Basename,
                $SaveHeight,
                $SaveWidth, // change these configs and add quality etc.
                array('OutputType' => $imageType, 'ImageQuality' => C('Garden.UploadImage.Quality', 75))
            );
    
  • Will consider adding transparency support for image uploads in a future release. Thanks, @agcyphers! :)

    Add Pages to Vanilla with the Basic Pages app

  • If you set the second parameter of GenerateTargetName to FALSE, it will figure out the extension by itself.

  • edited February 2015

    @Bleistivt, thanks for the tip! I'll probably set the second argument to false for the $UploadImage->GenerateTargetName() call. Also, it looks like validating the extension against an array of allowed extensions isn't necessary as $UploadImage->ValidateUpload() throws an exception for uploads that aren't images.

    Add Pages to Vanilla with the Basic Pages app

  • The purpose of that validation was to have a default extension of jpg if no others were found. Probably not the best way to do it.

Sign In or Register to comment.