rapila / cms-base

The rapila cms’ internals. Please file all issues here if they’re not directly related to a plugin or the sample site.

Home Page:http://www.rapi.la

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Preserve transparency when resizing png images

juergmessmer opened this issue · comments

I tried to analyze why transparency is not preserved when an image is resized and found out the version_compare doesn't work the way I'd expect it.

My local GD Version is “bundled (2.1.0 compatible)”. Though this version seems to be a newer version than the one (“2.0.1”) compared with, version_compare returns false. When I ignore this for test purposes, then the image is reduced and the transparency is perfectly preserved. (Image::resizeImage() line 251)

You can use a regex to extract 2.1.0 from the string "bundled (2.1.0 compatible)" and then compare against that.

Something like preg_replace("/.*((\\d+\\.){1,2}\\d).*/", '$1', self::$GD_INFO['GD Version']).

Using preg_match() the way you suggest returns no matches. If I replace “{2}” by “{2,1}” or remove it then the first result is “2.1.”. Is the handling of the period the problem or 0?

I said “something like”. I don’t have a computer to test the code.

Ok, thanks. Well I guess it this case this would do the job?
preg_match("/[0-9.]+/", self::$GD_INFO['GD Version'], $aMatches);

Maybe this is too loose? It may match the “9” in “9 times bundled (2.1.0 compatible)” (yes, that’s a fictional example).

I guess it's ok, since it's used in a very specific context (GD only).

I don’t know all the possible values to the GD Info string, so I don’t know whether the context is specific enough. Do you?

I’ve tested it now. Use preg_replace("/.*?((\\d+\\.){1,2}\\d+).*/", '$1', self::$GD_INFO['GD Version'])