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

Error, if zc=1 and RU locale #138

Open
AndreyMyagkov opened this issue Mar 20, 2019 · 2 comments
Open

Error, if zc=1 and RU locale #138

AndreyMyagkov opened this issue Mar 20, 2019 · 2 comments

Comments

@AndreyMyagkov
Copy link

Please use setLocale (LC_ALL, "en_US.UTF-8")

If outer script set RU locale phpThumb (zc=1) generated broken image

@dmpol18
Copy link

dmpol18 commented Mar 20, 2019

Actually the issue lies in phpthumb class when it generates command line for ImageMagick.

In this chunk of code

$wAll = (int) max($this->w, $this->wp, $this->wl, $this->ws) - (2 * $borderThickness);
$hAll = (int) max($this->h, $this->hp, $this->hl, $this->hs) - (2 * $borderThickness);
$imAR = $this->source_width / $this->source_height;
$zcAR = (($wAll && $hAll) ? $wAll / $hAll : 1);
$side  = phpthumb_functions::nonempty_min($this->source_width, $this->source_height, max($wAll, $hAll));
$sideX = phpthumb_functions::nonempty_min($this->source_width,                       $wAll, round($hAll * $zcAR));
$sideY = phpthumb_functions::nonempty_min(                     $this->source_height, $hAll, round($wAll / $zcAR));

$thumbnailH = round(max($sideY, ($sideY * $zcAR) / $imAR));
if ($this->aoe == 1) {
    $commandline .= ' -'.$IMresizeParameter.' "'.$wAll.'x'.$hAll.'^"';
} else {
    $commandline .= ' -'.$IMresizeParameter.' '.phpthumb_functions::escapeshellarg_replacement(($IMuseExplicitImageOutputDimensions ? $thumbnailH : '').'x'.$thumbnailH);
}

This part gives either float(1.5) or float(1,5) depending on setted locale.
$imAR = $this->source_width / $this->source_height;
Locale setting affects number format when it prints. Some details are here:
http://mark-story.com/posts/view/php-floats-localization-and-landmines
https://stackoverflow.com/questions/43345915/php-decimal-value-in-array-changes-automatically-from-point-to-comma-as-seperato

So one of the option could be using number_format function. Probably
$imAR = number_format (($this->source_width / $this->source_height), 2, '.');

Resulting line looks like this
convert '/path/test.jpg[0]' -flatten -density '150' -background '#FFFFFF' -thumbnail 'x2,0E+2' -gravity center -crop '201x201+0+0' +repage -quality '85' -interlace line jpeg:'/path/cache/pThumbbFkvI7' 2>&1
Pay attention to -thumbnail 'x2,0E+2' it also prints as -thumbnail 'x2.0E+2'
You can use this locale for debugging
setlocale(LC_ALL, 'ru_RU.UTF-8');

@JamesHeinrich
Copy link
Owner

Please submit a pull request with your suggested modifications and I'll merge it.

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

No branches or pull requests

3 participants