April 15, 2025 in Laravel
sqlstate[hy000] [2002] connection refused in laravel
change from 127.0.0.1 to localhost in the .env file and fixed this issue
DB_HOST=localhost
April 15, 2025 in Laravel
change from 127.0.0.1 to localhost in the .env file and fixed this issue
DB_HOST=localhost
$PostImage = $_POST['PostImage'];
$imageBlob = base64_decode(str_ireplace('data:image/png;base64,','',$PostImage));
$im = new Imagick();
$im->readImageBlob($imageBlob);
//$im = new Imagick($_FILES['imageForPost']["tmp_name"]);
$imageprops = $im->getImageGeometry();
$finalWidth = 512;
$finalHeight = 512;
$ext = '.png';
$size = 40;
$width = $imageprops['width'];
$height = $imageprops['height'];
if($height > $finalHeight){
$newHeight = $finalHeight;
$newWidth = ($finalHeight / $height) * $width;
}else{
$newWidth = $imageprops['width'];
$newHeight = $imageprops['height'];
}
$im->scaleImage($finalWidth,$finalHeight,true,true);
$canvas = new Imagick();
$canvas->newImage($finalWidth, $finalHeight, 'white', 'png');
$canvas->blurImage(25, 5);
$imageprops = $im->getImageGeometry();
$newWidth = $imageprops['width'];
$newHeight = $imageprops['height'];
if($finalWidth == $finalHeight){
$pos = 0;
$posh = ($finalHeight - $newHeight)/2;
}else{
$pos = ($finalWidth - $newWidth)/2;
$posh = ($finalHeight - $newHeight)/2;
}
$canvas->compositeImage($im, Imagick::COMPOSITE_OVER, $pos, $posh);
$canvas->setOption('jpeg:extent', $size.'kb');
$canvas->setImageFormat( "jpeg" );
$thumbnail = $im->getImageBlob();
$PostImage = $thumbnail;
echo "<img src='data:image/jpg;base64,".base64_encode($thumbnail)."' />";
$PostImage = $_POST['PostImage'];
$imageBlob = base64_decode(str_ireplace('data:image/png;base64,','',$PostImage));
$im = new Imagick();
$im->readImageBlob($imageBlob);
//$im = new Imagick($_FILES['imageForPost']["tmp_name"]);
$imageprops = $im->getImageGeometry();
$finalWidth = 512;
$finalHeight = 512;
$ext = '.png';
$size = 100;
$name = time().$ext;//$_FILES["image"]["name"];
$width = $imageprops['width'];
$height = $imageprops['height'];
if($height > $finalHeight){
$newHeight = $finalHeight;
$newWidth = ($finalHeight / $height) * $width;
}else{
$newWidth = $imageprops['width'];
$newHeight = $imageprops['height'];
}
$im->scaleImage($finalWidth,$finalHeight,true,true);
$im->setOption('png:extent', $size.'kb');
$im->setImageFormat( "png" );
header("Content-Type: image/png");
echo $im;
September 13, 2024 in Laravel
To install Laravel 10 on shared hosting and handle the issue with the public directory, you can follow these steps:
public Directory:
public directory to the root directory of your domain (often public_html or htdocs)..htaccess and index.php files from the public directory to the root directory.index.php:index.php file in the root directory to update the paths to autoload.php and app.php:require __DIR__.'/../vendor/autoload.php'; $app = require_once __DIR__.'/../bootstrap/app.php'; Change these lines to (assuming that the rest of your Laravel app is one level above the public_html):Copyrequire __DIR__.'/../your-laravel-directory/vendor/autoload.php'; $app = require_once __DIR__.'/../your-laravel-directory/bootstrap/app.php';.htaccess File:.htaccess file in your root directory, create one./public from the URL:<IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^(.*)$ public/ [L] </IfModule><IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} (.+)/$ RewriteRule ^ %1 [L,R=301] RewriteRule ^(.*)$ public/ [L] </IfModule> This will remove the trailing slash for non-directory requests and then rewrite the request to the public directory./vendor or your .env file, you can add additional rules to your .htaccess file:<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_URI} ^/(vendor|storage|.env)(/|$) RewriteRule ^ - [F,L,NC] </IfModule>Remember to replace your-laravel-directory with the actual directory name where your Laravel application resides on the server. Also, ensure that your server meets all the requirements for running Laravel 10, such as PHP version and necessary PHP extensions.
August 10, 2024 in Laravel
To come over this issue, you have to execute all the below commands:
php artisan route:cache
php artisan route:clear
php artisan config:cache
php artisan config:clear
php artisan optimize
The problem is that the project made a cache file. ‘config.php’ must be deleted in order to allow the system to restart and you can do so by locate this file and deleting it:
bootstrap/cache/config.php
May 1, 2024 in Advertisement, Laravel, Php
$question_attempt =$question_attempt + json_decode($data[0]->question_attempt,true);
array_merge not work with keys
$question_ids = array_merge($question_ids,json_decode($data[0]->question_ids,true));
April 30, 2024 in Laravel, Php
$affectedRows = DB::table('practice_done')->where([['user_id', $user_id],['practice_date', $practice_date],['language_code', $language_code]])->update(array('question_ids' => $question_ids,'question_attempt' => $question_attempt,'updated_at'=>$date));
<?php
/* Create some objects */
$image = new Imagick();
$draw = new ImagickDraw();
$pixel = new ImagickPixel( ‘gray’ );
/* New image */
$image->newImage(800, 75, $pixel);
/* Black text */
$draw->setFillColor(‘black’);
/* Font properties */
$draw->setFont(‘Bookman-DemiItalic’);
$draw->setFontSize( 30 );
/* Create text */
$image->annotateImage($draw, 10, 45, 0,
‘The quick brown fox jumps over the lazy dog’);
/* Give image a format */
$image->setImageFormat(‘png’);
/* Output the image with headers */
header(‘Content-type: image/png’);
echo $image;
February 26, 2024 in Laravel, Php
if(isset( $_FILES["image"] ) && !empty( $_FILES["image"]["name"] ))
{
$drive = "drive/temp/";
$im = new Imagick( $_FILES["image"]["tmp_name"]);
$finalWidth = $_POST['width'];
$finalHeight = $_POST['height'];
$size = $_POST['size'];
$name = time().".jpg";//$_FILES["image"]["name"];
$imageprops = $im->getImageGeometry();
$width = $imageprops['width'];
$height = $imageprops['height'];
if($height > $finalHeight){
$newHeight = $finalHeight;
$newWidth = ($finalHeight / $height) * $width;
}else{
$newWidth = $imageprops['width'];
$newHeight = $imageprops['height'];
}
//$im->resizeImage($newWidth,$newHeight, Imagick::FILTER_MITCHELL, 0.9, true);
$im->scaleImage(0, $finalHeight);
if(isset( $_FILES["imagebg"] ) && !empty( $_FILES["imagebg"]["name"] ) )
{
$canvas = new Imagick($_FILES["imagebg"]["tmp_name"]);
$canvas->resizeImage($finalWidth, $finalHeight, Imagick::FILTER_LANCZOS,1);
}else
{
$canvas = new Imagick();
$canvas->newImage($finalWidth, $finalHeight, $_POST['bgcolor'], 'jpg');
}
$canvas->blurImage(25, 5);
$pos = ($finalWidth - $newWidth)/2;
$canvas->compositeImage($im, Imagick::COMPOSITE_OVER, $pos, 0);
$canvas->setOption('jpeg:extent', $size.'kb');
$canvas->setImageFormat( "jpeg" );
//$im->blurImage(25, 5);
//$im->adaptiveSharpenImage(10,5);
//$im->unsharpMaskImage(0, 0.5, 1, 0);
//$im->setImageResolution( 800, 300 );
//$im->setResolution(800,300);
//$im->resampleImage (800,300,imagick::RESOLUTION_PIXELSPERINCH,1);
//$im->cropThumbnailImage( 800, 300 );
//$im->setImageCompressionQuality(70);
//$im->setImageCompression(true);
//$im->scaleImage(0, 300);
//$im->adaptiveResizeImage(800,300);
//$im->liquidRescaleImage(800, 300, 3, 18);
//$im->resizeImage(800, 300, Imagick::FILTER_LANCZOS,1);
//$im->sharpenImage(0, 3);
//$im->adaptiveBlurImage(5, 1, 0);
if (file_exists($drive.$name)) {
try{
unlink($drive.$name);
}
catch(Exception $ex)
{
echo $ex->getMessage()."Adi";
}
}
$canvas->writeImage($drive.$name);
//print_r($canvas->identifyImage());
return redirect("image-resizer")->withSuccess('drive/temp/'.$name);
}
return view('imageresizer',['name'=>'drive/temp/'.$name,'title'=>'Online Image Resizer','isUpload'=>1]);
February 24, 2024 in Laravel, Php
$file = $request->file('image');
$im = new Imagick( $file->getPathName());
$im = new Imagick( $_FILES["image"]["tmp_name"] );