Friday, August 24, 2018

how to convert PNG32 to PNG8 via Imagick in PHP

I want to convert PNG32 to PNG8 via the php Object Imagick. but I used setImageDepth and setImageFormat setting param to 8bit, it didn't take effect. the code like this:

$im = new Imagick($image);
$im->cropImage($cutWidth,$cutHeight,$x,$y);
$im->thumbnailImage($maxWidth, $maxHeight); 
$im->setImageDepth(8);
$im->setImageFormat('PNG8');
$im->writeImage($filename);

inputfile is PNG32, but output above remains PNG8, have other solution?

Solved

This seems to be a known problem, so I did some research. Basically, the setImageDepth just isn't enough. You need to quanitize the image. This is a test script that worked for me...

$im = new imagick('stupid.png'); //an image of mine
$im->setImageFormat('PNG8');
$colors = min(255, $im->getImageColors());
$im->quantizeImage($colors, Imagick::COLORSPACE_RGB, 0, false, false );
$im->setImageDepth(8 /* bits */);
$im->writeImage('stupid8.png');

Came out nice.


I know this is an old question that has already been answered but there is one other shorter way to do this that I discovered. You can force the write format by prefixing the filename with the format (e.g. png8:outputfile.png). The question example could be accomplished like this:

$im = new Imagick($image);
$im->cropImage($cutWidth,$cutHeight,$x,$y);
$im->thumbnailImage($maxWidth, $maxHeight); 
$im->writeImage("png8:$filename");

Monday, August 20, 2018

How to wrap parameter in VS Code?

What is the right setting for wrapping parameter in VS Code on the same level?

This is what i have:

constructor(private stateParams: angular.ui.IStateParamsService, 
  private $interval: angular.IIntervalService) {

This is what i would like to:

constructor(private stateParams: angular.ui.IStateParamsService, 
            private $interval: angular.IIntervalService) {

Solved

I'd also like to know how, shame this is not implemented by default..

The only workaround I could come up with is to install a plugin like Better Align and do the following :

constructor(
    private translate:    TranslateService,
    private _titleSetter: TitleSetterService,
    private _i18nLoader:  TranslationFilesLoaderService,
    private _router:      Router,
    private _formBuilder: FormBuilder
) {

which, BTW, can be done without the plugin and would look like this :

constructor(
    private translate: TranslateService,
    private _titleSetter: TitleSetterService,
    private _i18nLoader: TranslationFilesLoaderService,
    private _router: Router,
    private _formBuilder: FormBuilder
) {

but it provides you some other features on how to align your code.

Hope it helps a bit..


Perhaps this?

"editor.wrappingIndent": "same"

Sunday, August 19, 2018

nodetool repair taking a long time to complete

I am currently running Cassandra 3.0.9 in a 18 node config. We loaded quite a bit of data and now are running repairs against each node. My nodetool command is scripted to look like:

nodetool repair -j 4 -local -full

Using nodetool tpstats I see the 4 threads for repair but they are repairing very slowly. I have 1000's of repairs that are going to take weeks at this rate. The system log has repair items but also "Redistributing index summaries" listed as well. Is this what is causing my slowness? Is there a faster way to do this?

Solved

Repair can take a very long time, sometime days, sometime weeks. You might improve things with the following:

  1. Run primary partition range repair (-pr) This will repair only the primary partition range of each node, which overall, will be faster (you still need to run a repair on each node, one at a time).
  2. Using -j is not necessarily a big winner. Sure, you will repair multiple tables at a time, but you put much more load on your cluster, which can damage your latency.
  3. You might want to prioritize repairing the keyspaces / tables that are most critical to your application.
  4. Make sure you keep your node density reasonable. 1 to 2TB per node.
  5. Focus repairing in priority the nodes that went down for more than 3 hours (assuming max_hint_window_in_ms is set to it's default value)
  6. Focus repairing in priority the tables for which you create tombstones (DELETE statements)

Friday, August 17, 2018

Trigger my shell script which is available in remote server using Phpseclib

I am very much new with Phpseclib, and I am trying to sh/execute shell script available on my remote server using Phpseclib

set_include_path(get_include_path() . PATH_SEPARATOR . 'lib/phpseclib1.0.5');
include('lib/phpseclib1.0.5/Net/SSH2.php');
define('NET_SSH2_LOGGING', NET_SSH2_LOG_COMPLEX);
include_once ("admin/model/JobDAO.php");
$ssh = new Net_SSH2('192.168.11.68');
if (!$ssh->login('amit', 'password')) {
exit('Login Failed');
}
$ssh->setTimeout(1000);
$deployment_script="./InstallJava-Final.sh";
$ssh->exec(
    $deployment_script, function ($str) {
        echo $str;
        flush();
        ob_flush();
    });

?>

Above PHP code trigger my shell script InstallJava-Final.sh which is available in the remote server and show the output on the browser that It's downloading java from oracle website using wget but few second later the process Stopped.

browser output

My remote script should run properly without interruption/stop with root user