Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sherl0ck's avatar

Php image convert to jpg

I want to save the image to be uploaded as jpg imagejpeg

$hedef = "upload";
        $kaynak = $_FILES["image"]["tmp_name"]; 
        $name =  $_FILES["image"]["name"];
		$newimages=$txt_listnum."-".mt_rand()."-fieldotels-".$name;
		$extension = pathinfo($newimages, PATHINFO_EXTENSION);
        $save = move_uploaded_file($kaynak,$hedef."/".$newimages);
		

mysqli_query($con,"UPDATE fields SET listnum='$txt_listnum',name='$txt_name',location='$txt_location',path='$newimages' WHERE id='$id' ");
0 likes
8 replies
Sinnbeck's avatar

Start by formatting your code. Add ``` on the line before and after your code.

1 like
Sinnbeck's avatar

@sherl0ck but the file can be any other image format? Can you use packages from packagist/composer ?

sherl0ck's avatar

@Sinnbeck I have a simple panel. jpg png images are loaded from this panel if it uploads png, I want it to convert it to jpg format and save it to both the file path and the database.

sherl0ck's avatar

@Sinnbeck sory ı cant use . I'm trying to integrate

$im = new imagick($image);

// convert to png
$im->setImageFormat('png');

//write image on server
$im->writeImage($image .".png");
$im->clear();
$im->destroy(); 

Please or to participate in this conversation.