Set locale & custom thumb drivers

Does anyone has an idea why

c::set('locale', 'de_DE.UTF-8')
c::set('timezone','Europe/Berlin');
c::set('date.handler', 'strftime');

breaks a custom thumb driver, which is defined like this:

c::set('thumbs.driver', 'imcustom');
thumb::$defaults['bin'] = '/Applications/MAMP/Library/bin/convert';
thumb::$defaults['memory'] = '128MB';
```

it works if I set everything expect LC_NUMERIC:

```
c::set('locale', array(
  LC_COLLATE  => 'de_DE.UTF-8',
  LC_MONETARY => 'de_DE.UTF-8',
  //LC_NUMERIC  => 'de_DE.UTF-8',
  LC_TIME     => 'de_DE.UTF-8',
  LC_MESSAGES => 'de_DE.UTF-8',
  LC_CTYPE    => 'de_DE.UTF-8'
));
```

Thanks in advance for your help.

Hm, just guessing, but maybe this is due to numeric calculations with floating points. I remember I once had an issue with the Guggenheim plugin due to LC_NUMERIC settings ā€¦

What is the code for your thumb driver imcustom?

minor tests and adjustments in compared to the normal one.

<?

thumb::$drivers['imcustom'] = function($thumb) {

  $command = array();

  $command[] = isset($thumb->options['bin']) ? $thumb->options['bin'] : 'convert';
  $command[] = '"' . $thumb->source->root() . '"';
  // $command[] = '-strip'; keeping color profile
  $command[] = '-density 72';
  $command[] = '-profile IPTC';

  if($thumb->source->extension() === 'gif') {
    $command[] = '-coalesce';
  }

  if($thumb->options['grayscale']) {
    $command[] = '-colorspace gray';
  }

  if($thumb->options['autoOrient']) {
    $command[] = '-auto-orient';
  }

  $command[] = '-resize';

  if($thumb->options['crop']) {
    $command[] = $thumb->options['width'] . 'x' . $thumb->options['height'] . '^';
    $command[] = '-gravity Center -crop ' . $thumb->options['width'] . 'x' . $thumb->options['height'] . '+0+0';
  } else {
    $dimensions = clone $thumb->source->dimensions();
    $dimensions->fitWidthAndHeight($thumb->options['width'], $thumb->options['height'], $thumb->options['upscale']);
    $command[] = $dimensions->width() . 'x' . $dimensions->height() . '!';
  }

  $command[] = '-quality ' . $thumb->options['quality'];

  if($thumb->options['blur']) {
    $command[] = '-blur 0x' . $thumb->options['blurpx'];
  }

  $command[] = '"' . $thumb->destination->root . '"';

  exec(implode(' ', $command));

};

?>

That shouldnā€™t be the reason. Does it blow up with the default im driver as well?

BTW: I donā€™t recommend using PHP short tags. They are not usable in every PHP installation and can conflict with XML open tags, e.g. in sitemap templates.

That shouldnā€™t be the reason. Does it blow up with the default im driver as well?

No.

BTW: I donā€™t recommend using PHP short tags. They are not usable in every PHP installation and can conflict with XML open tags, e.g. in sitemap templates.

You are absolutely right. Lazy tests.

Have you tried to comment out the single commands in your custom driver to find out which one causes the problem?

It also happen if I copy 1:1 the code from the thumb.php

Wow, thatā€™s a strange bug. To be honest I canā€™t really tell whatā€™s happening. The thumb drivers are just functions that get stored in a static array, so thereā€™s nothing that should be different between a core thumb driver and the same one in a plugin.

Do you get any error message? Maybe it can lead us to a bug.

I tested your code with the above settings and could not reproduce this. What exactly do I have to put where to reproduce the error? And in what way does the site break?

The site doesnā€™t break but no thumbs are created with $image->crop(). The original file is return.

When setting the locale for numbers in PHP to German and you echo a float value, PHP will use a comma as a decimal point instead of a dot. For example, something like this will lead to an error:

<?php
setlocale(LC_ALL, 'de_DE.UTF-8');
$width = 140.5;
?>

<div style="width: <?= $width ?>%;">
<!-- result: <div style="width: 140,5%;"> -->

Without being able to test your code right now, your problem could be related to a float being converted to a string ā€“ and instead of a dot as decimal point, PHP will use a comma according to German orthography. This can be fixed by using the number_format() function, instead of just converting floats to strings. Maybe this is a starting point for further research ā€¦

That was my very first idea as well as outlined above, but how would that explain why the default driver works and the custom one does not, not even with the exact same commands?

@jensfranke:
Does your webserver run on Windows OS?

Then all ā€œlocaleā€ fields have to be set empty ( = ā€˜ā€™).

http://php.net/manual/en/function.setlocale.php:

Note:
On Windows, setlocale(LC_ALL, '') sets the locale names from the systemā€™s regional/language settings (accessible via Control Panel).

Hello,
Iā€™m sorry that I re-experience this topic.
But Iā€™m unable to set my locale to german.

c::set('locale', 'de_DE.UTF-8');
c::set('timezone','Europe/Berlin');
c::set('date.handler', 'strftime');

But my output is still -> 14. May 15
I want 14. Mai 15

Thanks ya for any answer,
Sebastian

I might be necessary to try different locale names, e.g. c::set('locale', 'de_DE.utf8'); or just de or something like that.

Did not work either, would be nice if someone have ideas too.

Greetings,
Sebastian

Could you please post what you have in your template? Are you on localhost or remote? Which OS?

Hey texnixe,
currently i am on a windows pc with localhost and a xampp server (switching between mamp osx and xampp windows)

My article template:

title: Article

pages: false

fields:
  title:
    label: Title
    type:  title

  date:
    icon: calendar
    label: Date
    type: date
    format: LL
    placeholder: Select a dateā€¦
    default: today
    required: true

  text:
    label: Text
    type: textarea

My listing.php for the article loop:

<section class="posts">
    <?php if($articles->count()): ?>
        <?php foreach($articles as $article): ?>
            <article class="post">
                
                <h1><?= $article->title()->kirbytext() ?></h1>

                <div class="text"><?= $article->text()->kirbytext() ?></div>
                <hr>
                <div class="post-link">
                    <?php echo strftime('%d. %B %y',$article->date()) ?> | <a href="<?php echo $article->url() ?>">Kommentierenā€¦</a>
                </div>
            </article>
        <?php endforeach ?>
    <?php else: ?>
        <p>This blog does not contain any articles yet.</p>
    <?php endif ?>
</section>

Greetings,
Sebastian

Have you tried to set the locale to an empty string as suggested above? Not really familiar with Windows, Iā€™m afraid.