Warning: getimagesize(blogimg/A2.jpg): failed to open stream: No such file or directory in C:\xampp\htdocs\LTF\Web\admin\SimpleImage.php on line 9
Warning: imagesx() expects parameter 1 to be resource, null given in C:\xampp\htdocs\LTF\Web\admin\SimpleImage.php on line 41
Warning: imagesy() expects parameter 1 to be resource, null given in C:\xampp\htdocs\LTF\Web\admin\SimpleImage.php on line 44
Warning: imagecopyresampled() expects parameter 2 to be resource, null given in C:\xampp\htdocs\LTF\Web\admin\SimpleImage.php on line 63
Aca el codigo que uso de mi archivo
Código PHP:
<?php
if(isset($_POST["enviar"])){
$i = isset($_GET['i']) ? $_GET['i'] : null;
include("simpleimage.php");
$php composer.phar require intervention/image
$sql=mysqli_query($conn , "SELECT * FROM blog ORDER BY `id` ASC ");
if($_POST["titulo"]=="" and $_POST["mensaje"]==""){
$b=2;
}
else{
$b=1;
while($rs= mysqli_fetch_array($sql)){
$i = $rs["id"] + 1;
}
//foto
if($_FILES["foto"]["name"]==""){
$imagena="";
$thumb ="";
echo "aaaaaaaaaaaa";
}
else{
echo "estoy aca";
$ext = strrchr($_FILES["foto"]["name"],'.');
$id_foto = "A".$i;
$id_foto_db="blogimg/".$id_foto."".$ext;
$id_foto_thumb="blogimg/thumb/".$id_foto."".$ext;
move_uploaded_file($_FILES["foto"]["tmp_name"],$id_foto_db."".$ext);
$imagena = $id_foto_db;
$thumb = $id_foto_thumb;
$image = new SimpleImage();
$image->load($id_foto_db);
$image->resize(148,142);
$image->save($id_foto_thumb);
}
$hoy = date("Y-m-d H:i:s");
mysqli_query($conn , "insert into blog (titulo,fecha,noticia,foto,thumb) values ('".$_POST['titulo']."','".$hoy."','".$_POST['mensaje']."','".$imagena."','".$thumb."')");
}
}
?>
Código PHP:
<?php
ini_set("memory_limit","1000M");
class SimpleImage {
var $image;
var $image_type;
function load($filename) {
$image_info = getimagesize($filename);
$this->image_type = $image_info[2];
if( $this->image_type == IMAGETYPE_JPEG ) {
$this->image = imagecreatefromjpeg($filename);
} elseif( $this->image_type == IMAGETYPE_GIF ) {
$this->image = imagecreatefromgif($filename);
} elseif( $this->image_type == IMAGETYPE_PNG ) {
$this->image = imagecreatefrompng($filename);
}
}
function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) {
if( $image_type == IMAGETYPE_JPEG ) {
imagejpeg($this->image,$filename,$compression);
} elseif( $image_type == IMAGETYPE_GIF ) {
imagegif($this->image,$filename);
} elseif( $image_type == IMAGETYPE_PNG ) {
imagepng($this->image,$filename);
}
if( $permissions != null) {
chmod($filename,$permissions);
}
}
function output($image_type=IMAGETYPE_JPEG) {
if( $image_type == IMAGETYPE_JPEG ) {
imagejpeg($this->image);
} elseif( $image_type == IMAGETYPE_GIF ) {
imagegif($this->image);
} elseif( $image_type == IMAGETYPE_PNG ) {
imagepng($this->image);
}
}
function getWidth() {
return imagesx($this->image);
}
function getHeight() {
return imagesy($this->image);
}
function resizeToHeight($height) {
$ratio = $height / $this->getHeight();
$width = $this->getWidth() * $ratio;
$this->resize($width,$height);
}
function resizeToWidth($width) {
$ratio = $width / $this->getWidth();
$height = $this->getheight() * $ratio;
$this->resize($width,$height);
}
function scale($scale) {
$width = $this->getWidth() * $scale/100;
$height = $this->getheight() * $scale/100;
$this->resize($width,$height);
}
function resize($width,$height) {
$new_image = imagecreatetruecolor($width, $height);
imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
$this->image = $new_image;
}
}
?>