Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Try Vanilla Forums Cloud product
Please upgrade to 2.3 here. The 2.2 and earlier branches are no longer being updated.

JPEG Only Supported

This discussion is related to the Articles addon.

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

Comments

  • agcyphersagcyphers Nooooop.

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

  • agcyphersagcyphers Nooooop.
    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))
            );
    
  • ShadowdareShadowdare π Moderator

    Will consider adding transparency support for image uploads in a future release. Thanks, @agcyphers! :)

    Add Pages to Vanilla with the Basic Pages app | Publish articles with the Articles app

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

    My themes: pure | minusbaseline - My plugins: CSSedit | HTMLedit | InfiniteScroll | BirthdayModule | [all] - PM me about customizations

  • ShadowdareShadowdare π Moderator
    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 | Publish articles with the Articles app

  • agcyphersagcyphers Nooooop.

    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.