function imageProcess($img_info)
{
    $file = $img_info['img_upload_url_temp'] . $img_info['img'];
    $sizeInfo = getimagesize($file);
    if (is_array($sizeInfo)) {
        include_once 'libraries/SimpleImage.php';
        $image = new SimpleImage();
        $image->load($file);
        $width = $sizeInfo[0];
        $height = $sizeInfo[1];
        //img thumb
        $img_thumb = $img_info['img_upload_url_thumb'] . $img_info['img'];
        if ($width <= IMAGE_THUMB_WIDTH && $height <= IMAGE_THUMB_HEIGHT) {
            copy($file, $img_thumb);
        } elseif ($width >= $height) {
            $image->resizeToWidth(IMAGE_THUMB_WIDTH);
            $image->save($img_thumb);
        } elseif ($width < $height) {
            $image->resizeToHeight(IMAGE_THUMB_HEIGHT);
            $image->save($img_thumb);
        }
        //img
        $img = $img_info['img_upload_url'] . $img_info['img'];
        if ($img_info['original'] == 1) {
            $image->load($file);
            if ($width >= $height && $width > IMAGE_MAX_WIDTH) {
                $image->resizeToWidth(IMAGE_MAX_WIDTH);
                $image->save($img);
            } elseif ($width <= $height && $height > IMAGE_MAX_HEIGHT) {
                $image->resizeToHeight(IMAGE_MAX_HEIGHT);
                $image->save($img);
            } else {
                copy($file, $img);
            }
            if (file_exists($file)) {
                unlink($file);
            }
        } else {
            if (copy($file, $img)) {
                if (file_exists($file)) {
                    unlink($file);
                }
            }
        }
        return true;
    } else {
        return false;
    }
}
Beispiel #2
0
function resizeImagesInFolder($dir, $i)
{
    if (!is_dir('cover/' . $dir)) {
        toFolder('cover/' . $dir);
    }
    $files = scandir($dir);
    foreach ($files as $key => $file) {
        if ($file != '.' && $file != '..') {
            if (!is_dir($dir . '/' . $file)) {
                echo $dir . '/' . $file;
                $image = new SimpleImage();
                $image->load($dir . '/' . $file);
                if ($image->getHeight() < $image->getWidth()) {
                    $image->resizeToWidth(1920);
                } else {
                    $image->resizeToHeight(1920);
                }
                // $new = 'cover/' . $dir . '/'.$image->name;
                if ($i < 10) {
                    $new = 'cover/' . $dir . '/00' . $i . '.' . $image->type;
                } elseif ($i < 100) {
                    $new = 'cover/' . $dir . '/0' . $i . '.' . $image->type;
                } else {
                    $new = 'cover/' . $dir . '/' . $i . '.' . $image->type;
                }
                $image->save($new);
                echo ' ---------> ' . $new . '<br>';
                $i++;
            } else {
                resizeImagesInFolder($dir . '/' . $file, 1);
            }
        }
    }
}
Beispiel #3
0
 function upload()
 {
     if (!isset($_FILES['upload'])) {
         $this->directrender('S3/S3');
         return;
     }
     global $params;
     // Params to vars
     $client_id = '1b5cc674ae2f335';
     // Validations
     $this->startValidations();
     $this->validate($_FILES['upload']['error'] === 0, $err, 'upload error');
     $this->validate($_FILES['upload']['size'] <= 10 * 1024 * 1024, $err, 'size too large');
     // Code
     if ($this->isValid()) {
         $fname = $_FILES['upload']['tmp_name'];
         require_once $GLOBALS['dirpre'] . 'includes/S3/SimpleImage.php';
         $image = new SimpleImage();
         $this->validate($image->load($fname), $err, 'invalid image type');
         if ($this->isValid()) {
             if ($image->getHeight() > 1000) {
                 $image->resizeToHeight(1000);
             }
             $image->save($fname);
             function getMIME($fname)
             {
                 $finfo = finfo_open(FILEINFO_MIME_TYPE);
                 $mime = finfo_file($finfo, $fname);
                 finfo_close($finfo);
                 return $mime;
             }
             $filetype = explode('/', getMIME($fname));
             $valid_formats = array("jpg", "png", "gif", "jpeg");
             $this->validate($filetype[0] === 'image' and in_array($filetype[1], $valid_formats), $err, 'invalid image type');
             if ($this->isValid()) {
                 require_once $GLOBALS['dirpre'] . 'includes/S3/s3_config.php';
                 //Rename image name.
                 $actual_image_name = time() . "." . $filetype[1];
                 $this->validate($s3->putObjectFile($fname, $bucket, $actual_image_name, S3::ACL_PUBLIC_READ), $err, 'upload failed');
                 if ($this->isValid()) {
                     $reply = "https://{$bucket}.s3.amazonaws.com/{$actual_image_name}";
                     $this->success('image successfully uploaded');
                     $this->directrender('S3/S3', array('reply' => "up(\"{$reply}\");"));
                     return;
                 }
             }
         }
     }
     $this->error($err);
     $this->directrender('S3/S3');
 }
function xulyImage($img, $urlImgTemp, $urlImg, $urlImgThumb, $original = 1)
{
    $file = $urlImgTemp . $img;
    $sizeInfo = getimagesize($file);
    if (is_array($sizeInfo)) {
        include_once 'libraries/SimpleImage.php';
        $image = new SimpleImage();
        $image->load($file);
        $width = $sizeInfo[0];
        $height = $sizeInfo[1];
        if ($width <= IMAGE_THUMB_WIDTH && $height <= IMAGE_THUMB_HEIGHT) {
            copy($file, $urlImgThumb . $img);
        } elseif ($width >= $height) {
            $image->resizeToWidth(IMAGE_THUMB_WIDTH);
            $image->save($urlImgThumb . $img);
        } elseif ($width < $height) {
            $image->resizeToHeight(IMAGE_THUMB_HEIGHT);
            $image->save($urlImgThumb . $img);
        }
        if ($original == 1) {
            $image->load($file);
            if ($width >= $height && $width > IMAGE_MAX_WIDTH) {
                $image->resizeToWidth(IMAGE_MAX_WIDTH);
                $image->save($urlImg . $img);
            } elseif ($width <= $height && $height > IMAGE_MAX_HEIGHT) {
                $image->resizeToHeight(IMAGE_MAX_HEIGHT);
                $image->save($urlImg . $img);
            } else {
                copy($file, $urlImg . $img);
            }
            if (file_exists($file)) {
                unlink($file);
            }
        } else {
            if (copy($file, $urlImg . $img)) {
                if (file_exists($file)) {
                    unlink($file);
                }
            }
        }
        return true;
    } else {
        return false;
    }
}
 public function executeAvatar(HTTPRequest $request)
 {
     ini_set("memory_limit", '256M');
     $this->page->smarty()->assign('avatar', $this->_profilePro->getAvatar());
     if ($request->fileExists('avatar')) {
         $avatar = $request->fileData('avatar');
         if ($avatar['error'] == 0) {
             $simpleImage = new SimpleImage();
             $simpleImage->load($avatar['tmp_name']);
             if (!is_null($simpleImage->image_type)) {
                 $height = $simpleImage->getHeight();
                 $width = $simpleImage->getWidth();
                 if ($height > $width) {
                     $simpleImage->resizeToHeight(150);
                 } else {
                     $simpleImage->resizeToWidth(150);
                 }
                 $filename = time() . '.jpg';
                 $simpleImage->save($_SERVER['DOCUMENT_ROOT'] . $this->_userDir . $filename);
                 if ($this->_profilePro->getAvatar() != ProfilePro::AVATAR_DEFAULT_PRO) {
                     unlink($_SERVER['DOCUMENT_ROOT'] . $this->_profilePro->getAvatar());
                 }
                 $this->_profilePro->setAvatar($this->_userDir . $filename);
                 $this->_profileProManager->save($this->_profilePro);
                 $this->app->user()->setFlash('avatar-updated');
             } else {
                 $this->app->user()->setFlash('avatar-error');
             }
         } else {
             $this->app->user()->setFlash('avatar-error');
         }
         $this->app->httpResponse()->redirect('/profile-pro');
     }
 }
Beispiel #6
0
 if (is_array($_FILES["file"]["error"])) {
     foreach ($_FILES["file"]["error"] as $key => $error) {
         if ($error == UPLOAD_ERR_OK) {
             $tmp_name = $_FILES["file"]["tmp_name"][$key];
             $name = $_FILES["file"]["name"][$key];
             move_uploaded_file($tmp_name, $uploadsDirectory . $hashtag . '-' . $name);
             $uploadedFiles[] = $hashtag . '-' . $name;
         }
     }
 }
 $image = new SimpleImage();
 foreach ($uploadedFiles as $upFiles) {
     //resizeImage
     $image->load($uploadsDirectory . $upFiles);
     $image->resizeToWidth(133);
     $image->resizeToHeight(110);
     $image->save($uploadsDirectoryThumb . $upFiles);
 }
 $category = explode(",", $_POST['inputCategory']);
 foreach ($category as $key => $val) {
     if ($val == "") {
         unset($category[$key]);
     } else {
         $cats = explode("-", $val);
         $category[$key] = $cats[1];
     }
 }
 $amenity = explode(",", $_POST['inputTags']);
 foreach ($amenity as $key => $val) {
     if ($val == "") {
         unset($amenity[$key]);
 private function savePhoto(AnnouncementPro $announce, $target, $file)
 {
     if ($file['error'] == 0) {
         $simpleImage = new SimpleImage();
         $thumbnailsSimpleImage = new SimpleImage();
         $simpleImage->load($file['tmp_name']);
         $thumbnailsSimpleImage->load($file['tmp_name']);
         if (!is_null($simpleImage->image_type)) {
             $height = $simpleImage->getHeight();
             $width = $simpleImage->getWidth();
             //Redimensionnement de l'image original en format modéré
             if ($height > 1200 || $width > 1600) {
                 if ($height > $width) {
                     $simpleImage->resizeToHeight(1200);
                 } else {
                     $simpleImage->resizeToWidth(1600);
                 }
             }
             //Redimensionnement de l'image original en miniature
             if ($height > $width) {
                 $thumbnailsSimpleImage->resizeToHeight(300);
             } else {
                 $thumbnailsSimpleImage->resizeToWidth(300);
             }
             $filename = $target . '-' . time() . '.jpg';
             $thumbnails = AnnouncementPro::THUMBNAILS_PREFIX . $filename;
             $simpleImage->save($_SERVER['DOCUMENT_ROOT'] . AnnouncementPro::ANNOUNCEMENT_PRO_DIRECTORY . $announce->id() . '/' . $filename);
             $thumbnailsSimpleImage->save($_SERVER['DOCUMENT_ROOT'] . AnnouncementPro::ANNOUNCEMENT_PRO_DIRECTORY . $announce->id() . '/' . $thumbnails);
             $getMethod = 'get' . $target;
             $setMethod = 'set' . $target;
             if ($announce->{$getMethod}() != AnnouncementPro::IMAGE_DEFAULT && $announce->{$getMethod}() != '') {
                 unlink($_SERVER['DOCUMENT_ROOT'] . AnnouncementPro::ANNOUNCEMENT_PRO_DIRECTORY . $announce->id() . '/' . $announce->{$getMethod}());
                 unlink($_SERVER['DOCUMENT_ROOT'] . AnnouncementPro::ANNOUNCEMENT_PRO_DIRECTORY . $announce->id() . '/' . AnnouncementPro::THUMBNAILS_PREFIX . $announce->{$getMethod}());
             }
             $announce->{$setMethod}($filename);
         }
     }
 }
Beispiel #8
0
                $boyutlar2 = mysql_fetch_array(mysql_query("select * from tlg_boyut where id='{$c}'"));
                $genislik = $boyutlar2["width"];
                $yukseklik = $boyutlar2["height"];
                $uzanti = substr($_FILES["resim"]["name"][$i], -4, 4);
                $klasor = "resimler/etkinlik/" . $genislik . "x" . $yukseklik . "/";
                $yeni_ad = $klasor . $nowdate . $saat . $uzanti;
                //klasorler oluşturuluyor
                //klasör açma
                if (is_dir($klasor)) {
                } else {
                    mkdir($klasor);
                    echo "<center>" . $klasor . ' Klasörü Oluşturuldu <i class="fa fa-check-square-o"></i></center>';
                }
                $image = new SimpleImage();
                $image->load($_FILES["resim"]["tmp_name"][$i]);
                $image->resizeToHeight($yukseklik);
                $image->save($yeni_ad);
                $sorgu = mysql_query("insert into tlg_etkinlikresim (resim_link,title,baslik_id,boyut,boyutkod) values ('{$yeni_ad}','{$aciklama}', '{$mid}' ,'{$c}','{$boyutkod}')");
            }
            if ($sorgu) {
                echo '<center>Veritabanına Eklendi.<i class="fa fa-check-square-o"></i></center>';
            } else {
                echo '<center>Kayıt sırasında hata oluştu!<i class="fa fa-frown-o"></i></center>';
            }
        }
    }
}
?>
<form action="" method="post" name="form1" enctype="multipart/form-data">
<?php 
$makaleid = $_GET["id"];
Beispiel #9
0
            $imagef->resizeToHeight($height);
            $imagef->save($file);
            $w = getimagesize($file);
            if ($w[0] > $width) {
                $imagef->resizeToWidth($width);
                $imagef->save($file);
            }
        } else {
            if ($w[0] >= $w[1]) {
                $imagef = new SimpleImage();
                $imagef->load($file);
                $imagef->resizeToWidth($width);
                $imagef->save($file);
                $w = getimagesize($file);
                if ($w[1] > $height) {
                    $imagef->resizeToHeight($height);
                    $imagef->save($file);
                }
            }
        }
        $itemid = $fs->create_file_from_pathname($file_record, $file);
        unlink($file);
        $c++;
    }
}
if (@$_FILES['i_audio']) {
    $c = 0;
    foreach ($_FILES['i_audio']['tmp_name'] as $k => $v) {
        ///Delete old records
        //$fs->delete_area_files($contextmodule->id, 'mod_mediaboard', 'private', $k);
        $file_record = new stdClass();
Beispiel #10
0
     mt_srand((double) microtime() * 1000000);
     while (strlen($fileName) < $len + 1) {
         $fileName .= $base[mt_rand(0, $max)];
     }
     //Determine the path to which we want to save this file
     //$newname = dirname(__FILE__).'/upload/'.$filename;
     //$newname = 'dirtpage/accounts/'.$filename;
     //$newname = 'dirtpage/html/accounts/'.$filename;
     $newName = '../pictures/' . $fileName . '.jpg';
     //Check if the file with the same name is already exists on the server
     if (!file_exists($newName)) {
         //Attempt to move the uploaded file to it's new place
         if (move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $newName)) {
             $image = new SimpleImage();
             $image->load($newName);
             $image->resizeToHeight(1000);
             $image->resizeToWidth(400);
             $image->save($newName);
             header('Location: http://www.dirtpage.com/page/?topic=' . $topic);
             mysql_query("INSERT INTO pictures (topic, picture, origin) VALUES('{$topic}', '{$fileName}',now()) ") or die(mysql_error());
             mysql_query("delete from postedon where topic = '{$topic}'") or die(mysql_error());
             mysql_query("INSERT INTO postedon\r\n(topic) VALUES('{$topic}')") or die(mysql_error());
         } else {
             echo "Error: A problem occurred during file upload!";
         }
     } else {
         echo "Error: File " . $_FILES["uploaded_file"]["name"] . " already exists";
     }
 } else {
     echo "Error: Only .jpg images under 10mb are accepted for upload";
     echo "size: " . $_FILES["uploaded_file"]["size"];
Beispiel #11
0
     $destino_temporal = tempnam("tmp/", "tmp");
     marcadeagua($origen, $marcadeagua, $destino_temporal, 100);
     // guardamos la imagen
     $fp = fopen($destino, "w");
     fputs($fp, fread(fopen($destino_temporal, "r"), filesize($destino_temporal)));
     fclose($fp);
     unlink($origen);
     rename($destino, $origen);
     $image = new SimpleImage();
     $image->load($origen);
     if ($anchura > $altura) {
         $res = 1;
         $image->resizeToWidth($maxSize);
     } else {
         $res = 0;
         $image->resizeToHeight($maxSize);
     }
     $image->save($dest . $dirf . "/" . $imagenr);
     if (file_exists($dest . $dirf . "/" . $imagenr)) {
         unlink($origen);
     } else {
         $error = 'Imagen de marca de agua NO Encontrada';
     }
 } else {
     $error = 'Imagen Resized NO Encontrada';
 }
 if (file_exists($dest . $dirf . "/" . $imagent) && file_exists($dest . $dirf . "/" . $imagenr)) {
     //echo "Proceso exitoso.<br>";
     echo "insert into fotos (id_galeria,description,alto_ancho) " . "values(" . $gal . ",'" . $imagenr . "'," . $res . ");<br>";
     $b++;
 } else {
Beispiel #12
0
    function upload($userid, $max_byte_size = 2097152)
    {
        global $debug;
        global $config;
        $dir = 'media/avatar/';
        $msg = '';
        // upload button has been pressed
        if (@$_POST['submit'] == 'Upload') {
            // set allowed file types
            $allowed_types = "(jpg|jpeg|gif|bmp|png)";
            // is really a file?
            if (is_uploaded_file($_FILES["file"]["tmp_name"])) {
                // valid extension?
                if (preg_match("/\\." . $allowed_types . "\$/i", $_FILES["file"]["name"])) {
                    // file size okay?
                    if ($_FILES["file"]["size"] <= $max_byte_size) {
                        // width and height okay?
                        $size = getimagesize($_FILES['file']['tmp_name']);
                        $debug->add('img-size', 'height:' . $size[0] . ' width:' . $size[1]);
                        // get user
                        $u = $this->user->getUserByID($userid);
                        $filename = uniqid($u['userid'] . "_") . "_" . $_FILES["file"]["name"];
                        // everything all right, now copy
                        if (!file_exists($dir . $filename)) {
                            if (copy($_FILES["file"]["tmp_name"], $dir . $filename)) {
                                // Resize image if too large
                                $image = new SimpleImage();
                                $image->load($dir . $filename);
                                if ($image->getWidth() > (int) $config->get('core', 'img-width')) {
                                    $image->resizeToWidth((int) $config->get('core', 'img-width'));
                                }
                                if ($image->getHeight() > (int) $config->get('core', 'img-height')) {
                                    $image->resizeToHeight((int) $config->get('core', 'img-height'));
                                }
                                // Save image
                                $this->remove($filename);
                                $image->save($dir . $filename);
                                // upload successfull
                                $msg = $this->lang->get('upload_successfull');
                                // remove old avatar
                                $this->remove($u['avatar']);
                                // update avatar
                                $this->user->setAvatar($userid, $filename);
                            } else {
                                $msg = $this->lang->get('upload_failed');
                            }
                        } else {
                            $msg = $this->lang->get('upload_failed');
                        }
                    } else {
                        $msg = $this->lang->get('upload_too_large');
                    }
                } else {
                    $msg = $this->lang->get('upload_bad_extension');
                }
            } else {
                $msg = $this->lang->get('upload_failed');
            }
        }
        // display the upload-form
        return '
				<p>
					' . $msg . '
				</p>
				
				<form action="" method="post" enctype="multipart/form-data" name="upload">
					
					<input type="file" name="file" />
					<input type="submit" name="submit" value="Upload" />
					
				</form> 
				
				';
    }
Beispiel #13
0
        }
    }
    if ($_FILES['image']['size'] > 0) {
        $upload = new Upload();
        $upload->dir = 'media/boximages/ad/';
        $upload->tag_name = 'image';
        $upload->uploadFile();
        $imgdir = "./media/boximages/ad/";
        include_once './core/simple.image.core.php';
        $image = new SimpleImage();
        $image->load($imgdir . $upload->file_name);
        if ($image->getWidth() > (int) $config->get('ad', 'standard_image_width')) {
            $image->resizeToWidth((int) $config->get('ad', 'standard_image_width'));
        }
        if ($image->getHeight() > (int) $config->get('ad', 'standard_image_height')) {
            $image->resizeToHeight((int) $config->get('ad', 'standard_image_height'));
        }
        unlink($imgdir . $upload->file_name);
        $image->save($imgdir . $upload->file_name);
        if (substr($_POST['newurl'], 0, 7) != "http://") {
            $_POST['newurl'] = "http://" . $_POST['newurl'];
        }
        $db->insert($tbl_ad, array('img', 'url'), array("'" . $upload->file_name . "'", "'" . $_POST['newurl'] . "'"));
    }
}
$allads = $db->selectList($tbl_ad, '*', 1);
$counter = 0;
$ads = array();
foreach ($allads as $ad) {
    $ads[$counter] = $ad;
    $ads[$counter++]['imgurl'] = makeUrl('ad', array('mode' => 'edit'));
Beispiel #14
0
 $r_date = date("d-m-Y");
 $uzanti = array('image/jpeg', 'image/jpg', 'image/png', 'image/x-png', 'image/gif');
 $dizin = "upload_images/" . uniqid('upload_images', true) . $_FILES['image_file']['name'];
 if (in_array(strtolower($_FILES['image_file']['type']), $uzanti)) {
     if ($_FILES['image_file']['size'] < "999999") {
         if (move_uploaded_file($_FILES['image_file']['tmp_name'], $dizin)) {
             $query = mysql_query("insert into lavazza_photoevent(fb_id,name,surname,email,phone,register_date,photo_url) values('{$fb_id}','{$name}','{$surname}','{$email}','{$phone}','{$r_date}','{$dizin}')");
             $image = new SimpleImage();
             $image->load($dizin);
             $image_width = $image->getWidth();
             $image_height = $image->getHeight();
             if ($image_width > 600 && $image_height > 600) {
                 $image->resize(600, 600);
             } else {
                 if ($image_height > 600) {
                     $image->resizeToHeight(600);
                 } else {
                     if ($image_width > 600) {
                         $image->resizeToWidth(600);
                     }
                 }
             }
             $image->save($dizin);
             echo "<meta http-equiv=\"refresh\" content=\"0; url=?go=success\">";
         }
     } else {
         echo "<meta http-equiv=\"refresh\" content=\"0; url=index.php?go=join_to_event&sk=error&type=size\">";
     }
 } else {
     echo "<meta http-equiv=\"refresh\" content=\"0; url=index.php?go=join_to_event&sk=error&type=file_type\">";
 }
Beispiel #15
0
 protected function processOrigLocal($localFile, $file)
 {
     if (file_exists($file)) {
         // error_log('Found file (1): ' . $relfile);
         DiscoUtils::debug('Using already cached file : ' . $file);
         return $file;
     }
     // if ($logo['height'] > 40) {
     $image = new SimpleImage();
     $image->load($localFile);
     $image->resizeToHeight(38);
     $image->save($file);
     if (file_exists($file)) {
         DiscoUtils::debug("Successfully resized logo and stored a new cached file.");
         return $file;
     }
     // }
     $orgimg = file_get_contents($localFile);
     file_put_contents($file, $orgimg);
     if (file_exists($file)) {
         DiscoUtils::debug('Using generated and cached file : ' . $file);
         return $file;
     }
 }
 // $typesArray = split('\|',$fileTypes);
 // $fileParts  = pathinfo($_FILES['Filedata']['name']);
 // if (in_array($fileParts['extension'],$typesArray)) {
 // Uncomment the following line if you want to make the directory if it doesn't exist
 mkdir(str_replace('//', '/', $targetPath), 0755, true);
 move_uploaded_file($tempFile, $targetFile);
 $image = new SimpleImage();
 $image->load($targetFile);
 if ($image->getWidth() > 600 || $image->getHeight() > 450) {
     //set proper width
     if ($image->getWidth() > 600) {
         $image->resizeToWidth(600);
     }
     //set proper height
     if ($image->getHeight() > 450) {
         $image->resizeToHeight(450);
     }
     $image->save($targetFile, IMAGETYPE_JPEG, 75, 0755);
     $newFile = str_replace('//', '/', $targetPath) . 'thumb_' . $file;
     $image->resize(155, 115);
     $image->save($newFile, IMAGETYPE_JPEG, 75, 0755);
 } else {
     $image->save($targetFile, IMAGETYPE_JPEG, 75, 0755);
     $newFile = str_replace('//', '/', $targetPath) . 'thumb_' . $file;
     $image->resize(155, 115);
     $image->save($newFile, IMAGETYPE_JPEG, 75, 0755);
 }
 //move_uploaded_file($tempFile, $targetFile);
 /*
  *  response JSON format
  */
Beispiel #17
0
    error_reporting(0);
    // $fileTypes  = str_replace('*.','',$_REQUEST['fileext']);
    // $fileTypes  = str_replace(';','|',$fileTypes);
    // $typesArray = split('\|',$fileTypes);
    // $fileParts  = pathinfo($_FILES['Filedata']['name']);
    // if (in_array($fileParts['extension'],$typesArray)) {
    // Uncomment the following line if you want to make the directory if it doesn't exist
    mkdir(str_replace('//', '/', $targetPath), 0755, true);
    move_uploaded_file($tempFile, $targetFile);
    $image = new SimpleImage();
    $image->load($targetFile);
    if ($image->getWidth() >= 600) {
        $newFile = str_replace('//', '/', $targetPath) . "full_" . $name;
        $image->resizeToWidth(600);
        $image->save($newFile, IMAGETYPE_JPEG, 75, 0755);
        $newFile = str_replace('//', '/', $targetPath) . "thumb_" . $name;
        $image->resizeToHeight(32);
        $image->save($newFile, IMAGETYPE_JPEG, 75, 0755);
    } else {
        $newFile = str_replace('//', '/', $targetPath) . "full_" . $name;
        $image->save($newFile, IMAGETYPE_JPEG, 75, 0755);
        $newFile = str_replace('//', '/', $targetPath) . "thumb_" . $name;
        $image->resizeToHeight(32);
        $image->save($newFile, IMAGETYPE_JPEG, 75, 0755);
    }
    //echo str_replace($_SERVER['DOCUMENT_ROOT'],'',$targetFile);
    echo $name;
    // } else {
    // 	echo 'Invalid file type.';
    // }
}
Beispiel #18
0
	protected static function getCachedLogo($logo) {
		
		$hash = sha1($logo['url']);
		$relfile = 'cached/' . $hash;
		$file = dirname(dirname(__FILE__)) . '/www/discojuice/logos/' . $relfile;
		$fileorig = $file . '.orig';

		if (file_exists($file)) {
			return $relfile;
		}
		
		//echo 'icon file: ' . $file; exit;
		
		$orgimg = file_get_contents($logo['url']);
		if (empty($orgimg)) return null;
		file_put_contents($fileorig, $orgimg);
		
		if ($logo['height'] > 40) {
			$image = new SimpleImage();
			$image->load($fileorig);
			$image->resizeToHeight(38);
			$image->save($file);

			if (file_exists($file)) {
				return $relfile;
			}	
		}
		
		file_put_contents($file, $orgimg);
		
		if (file_exists($file)) {
			return $relfile;
		}
		
	}
Beispiel #19
0
        }
    }
    reset($var);
    if ($id) {
        $datam['id'] = $id;
    }
    $id = insert_record("apps_clozeactivity", $datam);
    if ($_FILES['image']['tmp_name']) {
        list($width, $height, $type, $attr) = getimagesize($_FILES['image']['tmp_name']);
        if ($width > 180 || $height > 180) {
            $image = new SimpleImage();
            $image->load($_FILES['image']['tmp_name']);
            if ($width > $height) {
                $image->resizeToWidth(180);
            } else {
                $image->resizeToHeight(180);
            }
            $image->save($CFG['dirroot'] . "/datas/clozeactivity/image/{$id}.jpg");
        } else {
            move_uploaded_file($_FILES['image']['tmp_name'], $CFG['dirroot'] . "/datas/clozeactivity/image/{$id}.jpg");
        }
    }
    if ($_FILES['soundtext']['tmp_name']) {
        move_uploaded_file($_FILES['soundtext']['tmp_name'], $CFG['dirroot'] . "/datas/clozeactivity/soundtext/{$id}.mp3");
    }
    $status = statusmessage('Cloze activity - Added');
}
if ($act == "edit" && !empty($id)) {
    $data = get_record("apps_clozeactivity", array("id" => $id));
}
?>
Beispiel #20
0
function main()
{
    if (isset($_FILES['picturefile']['name'])) {
        $referersplit = preg_split("/[?]/", $_SERVER['HTTP_REFERER']);
        $referer = $referersplit[0];
        try {
            if ($_FILES["picturefile"]["size"] > 5 * 1024 * 1024 || $_FILES['picturefile']['tmp_name'] == null) {
                throw new Exception('File too large!');
            } else {
                if (getContentType($_FILES['picturefile']['name']) == null) {
                    throw new Exception('File type not supported!');
                } else {
                    $filename = generateUniqueId() . "-" . $_FILES['picturefile']['name'];
                    $tmpName = $_FILES['picturefile']['tmp_name'];
                    $image = new SimpleImage();
                    $image->load($tmpName);
                    $imageWasResized = false;
                    if ($image->getHeight() > 1024) {
                        $image->resizeToHeight(1024);
                    }
                    if ($image->getWidth() > 1024) {
                        $image->resizeToWidth(1024);
                    }
                    $image->save($tmpName);
                    // Saving even if not resized, to reduce compression level of file
                    $fp = fopen($tmpName, 'r');
                    $content = fread($fp, filesize($tmpName));
                    fclose($fp);
                    updateOrInsertImage($filename, $content);
                }
            }
            header('Location: ' . $referer . "?uploadresult=true&filelocation=php/io.php?file=" . $filename);
            return true;
        } catch (Exception $e) {
            header('Location: ' . $referer . "?uploadresult=false&errormsg=" . $e->getMessage());
            return true;
        }
    }
    if (isset($_GET['id'])) {
        $slideshowId = $_GET['id'];
        $slideshowSrc = getSlideshow($slideshowId);
        $slideshow = array('id' => $slideshowId, 'src' => $slideshowSrc);
        sendJSONResponse(json_encode($slideshow));
        return true;
    }
    if (isset($_POST['id'], $_POST['key'], $_POST['src'])) {
        $slideshowId = $_POST['id'];
        $slideshowKey = $_POST['key'];
        $slideshowToSave = $_POST['src'];
        if (isCorrectKey($slideshowId, $slideshowKey)) {
            updateSlideshow($slideshowId, $slideshowToSave);
        } else {
            throw new Exception("ERROR key is wrong");
        }
        $result = array('id' => $slideshowId);
        sendJSONResponse(json_encode($result));
        return true;
    }
    if (isset($_POST['create'])) {
        $id = generateUniqueId();
        $key = generateRandomLegibleString();
        createEmptySlideshow($id, $key);
        $idAndKey = array('id' => $id, 'key' => $key);
        sendJSONResponse(json_encode($idAndKey));
        return true;
    }
    if (isset($_GET['file'])) {
        $imageId = $_GET['file'];
        $image = getImage($imageId);
        header("Content-type: " . getContentType($imageId));
        print $image;
        return true;
    }
    return false;
}
Beispiel #21
0
if (!in_array($fileExt, $typesArray)) {
    die("error_filetype_not_allowed");
}
$relative_folder_path = "files/" . gmdate("Y-m") . "/images";
$absolute_folder_path = str_replace('//', '/', "{$_SESSION["root_path"]}/{$relative_folder_path}");
if (!is_dir($absolute_folder_path)) {
    mkdir($absolute_folder_path, 0755, true);
}
$random_fileNumber = gmdate("U_") . rand(0, 1000);
$filename = "{$random_fileNumber}__{$user->username}___{$fileParts['basename']}";
$file_absolute_path_fullsize = "{$absolute_folder_path}/{$filename}";
$file_absolute_path_thumbnail = "{$absolute_folder_path}/tn_{$filename}";
$file_relative_path_fullsize = "{$relative_folder_path}/{$filename}";
$file_relative_path_thumbnail = "{$relative_folder_path}/tn_{$filename}";
copy($_FILES['Filedata']['tmp_name'], $file_absolute_path_thumbnail);
move_uploaded_file($_FILES['Filedata']['tmp_name'], $file_absolute_path_fullsize);
$img = new SimpleImage();
$img->load($file_absolute_path_thumbnail);
$filetype = $img->image_type;
if ($img->getWidth() > $img->getHeight()) {
    $img->resizeToWidth(150);
} else {
    $img->resizeToHeight(150);
}
$img->save($file_absolute_path_thumbnail, $filetype);
$group = $_REQUEST["group"];
$created = gmdate("Y-m-d H:i:s");
if (!mysql_query("INSERT INTO `images_general` (`type`,`size`,`file_location`,`file_thumbnail`,`file_name`,`group`,`author`,`created`) VALUES ('{$fileExt}','" . filesize($_FILES['Filedata']['tmp_name']) . "','{$file_relative_path_fullsize}','{$file_relative_path_thumbnail}','{$fileParts['basename']}','{$group}','{$user->username}','{$created}')")) {
    die("database_error");
}
die("done");
Beispiel #22
0
}
// ******************************************** End Class *****************************************************
$p_img = $_GET["img"];
$model = $_GET["model"];
$style = $_GET["style"];
if ($p_img == '' || $model == '') {
    return;
}
header('Content-Type: image/jpeg');
$image = new SimpleImage();
$style = strtolower($style);
switch ($style) {
    case 'tmb':
        $image->load("models/{$model}/{$p_img}");
        $image->SetWatermark();
        $image->resizeToHeight(100);
        $image->output();
        break;
    case 'profile':
        //$image->load("models/$model/$p_img");
        $image->load("models/{$p_img}");
        $image->resizeToHeight(407);
        $image->crop(237);
        $image->SetWatermark();
        $image->output();
        break;
    case 'main':
        //$image->load("models/$model/$p_img");
        $image->load("models/{$p_img}");
        $image->resizeToHeight(402);
        // 217x402
    if ($DOC_FILE1 != NULL) {
        $photos_download_dir = "../../imgs/galeria/evento_" . $next_slide . "/";
        // create the new directory if it doesn't exist.
        if (!file_exists($photos_download_dir)) {
            mkdir($photos_download_dir, 0777, true);
        }
        // change spaces to underscores in filename
        $photo_name = 'portada.jpg';
        $photo_big = new SimpleImage();
        $photo_big->load($DOC_FILE1);
        if ($photo_big->getWidth() > 2080 || $photo_big->getHeight() > 1388) {
            if ($photo_big->getWidth() > 2080) {
                $photo_big->resizeToWidth(2080);
            }
            if ($photo_big->getHeight() > 1388) {
                $photo_big->resizeToHeight(1388);
            }
        }
        // save the photo into the videogallery directory.
        $photo_big->save($photos_download_dir . $photo_name, $DOC_FILE_TYPE1);
        //END CODE TO RESAMPLE AND UPLOAD PHOTO FILE.
    }
    unlink($DOC_FILE1);
    $insertSQL = "INSERT INTO eventos (id_evento, nombre, descripcion, portada, fecha_ini, fecha_fin) VALUES ('" . $next_slide . "','" . $_POST['nombre'] . "','" . $_POST['descripcion'] . "','" . $photo_name . "','" . $_POST['fecha_ini'] . "','" . $_POST['fecha_fin'] . "')";
    $Result1 = mysql_query($insertSQL, $elencuentro) or die(mysql_error());
    header("Location: index.php");
}
include '../header.php';
?>
<section>
	<form name="form" method="post" action="nuevo_evento.php" enctype="multipart/form-data" onSubmit="return validate();">
Beispiel #24
0
 $image_w = $si->getWidth();
 $image_h = $si->getHeight();
 //picture is horizontal
 if ($image_w > $image_h) {
     //don't stretch images
     if ($image_w > AT_PA_IMAGE) {
         $si->resizeToWidth(AT_PA_IMAGE);
         $si->save(AT_PA_CONTENT_DIR . $album_file_path . $photo_file_path);
     } else {
         move_uploaded_file($_FILES['photo']['tmp_name'], AT_PA_CONTENT_DIR . $album_file_path . $photo_file_path);
     }
     $si->resizeToWidth(AT_PA_IMAGE_THUMB);
     $si->save(AT_PA_CONTENT_DIR . $album_file_path_tn . $photo_file_path);
 } else {
     if ($image_h > AT_PA_IMAGE) {
         $si->resizeToHeight(AT_PA_IMAGE);
         $si->save(AT_PA_CONTENT_DIR . $album_file_path . $photo_file_path);
     } else {
         move_uploaded_file($_FILES['photo']['tmp_name'], AT_PA_CONTENT_DIR . $album_file_path . $photo_file_path);
     }
     $si->resizeToHeight(AT_PA_IMAGE_THUMB);
     $si->save(AT_PA_CONTENT_DIR . $album_file_path_tn . $photo_file_path);
 }
 if ($_POST['upload'] == 'ajax') {
     $photo_file_hash = getPhotoFilePath($added_photo_id, '', $photo_info['created_date']);
     //return JSON, relying on jQuery to convert entries to html entities.
     echo json_encode(array('aid' => $id, 'pid' => $added_photo_id, 'ph' => $photo_file_hash, 'size' => number_format(filesize(AT_PA_CONTENT_DIR . $album_file_path . $photo_file_path) / 1024, 2), 'title' => $photo_info['title'], 'alt' => $photo_info['alt']));
     $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
     exit;
 }
 //if this is profile picture upload, sets it to the default profile
Beispiel #25
0
function uploadImage($fileID, $directory, $imageWidth = NULL, $imageHeight = NULL, $thumbWidth = NULL, $thumbHeight = NULL)
{
    /*
    echo "imageWidth = |" . $imageWidth . "|<br />";
    echo "imageHeight = |" . $imageHeight . "|<br />";
    echo "thumbWidth = |" . $thumbWidth . "|<br />";
    echo "thumbHeight = |" . $thumbHeight . "|<br />";	
    */
    $FILE = $_FILES[$fileID]['tmp_name'];
    $FILE_NAME = $_FILES[$fileID]['name'];
    $fileName_final = cleanForShortURL($FILE_NAME);
    if ($FILE != NULL) {
        //////////// BIG IMAGE  /////////////////////////////////////////////////////////
        // If big image is required.
        if ($imageWidth != NULL || $imageHeight != NULL) {
            if (is_numeric($imageWidth) || is_numeric($imageHeight)) {
                // resample image
                $image = new SimpleImage();
                $image->load($FILE);
                if (is_numeric($imageWidth) && is_numeric($imageHeight)) {
                    if ($image->getWidth() > $imageWidth || $image->getHeight() > $imageHeight) {
                        if ($image->getWidth() > $imageWidth) {
                            $image->resizeToWidth($imageWidth);
                        }
                        if ($image->getHeight() > $imageHeight) {
                            $image->resizeToHeight($imageHeight);
                        }
                    }
                } else {
                    if (is_numeric($imageWidth) && !is_numeric($imageHeight)) {
                        if ($image->getWidth() > $imageWidth) {
                            $image->resizeToWidth($imageWidth);
                        }
                    } else {
                        if (!is_numeric($imageWidth) && is_numeric($imageHeight)) {
                            if ($image->getHeight() > $imageHeight) {
                                $image->resizeToHeight($imageHeight);
                            }
                        }
                    }
                }
                // if directory doesn't exist, it is created.
                if (!file_exists($directory)) {
                    mkdir($directory, 0777, true);
                }
                // save image into directory.
                $image->save($directory . $fileName_final);
            }
            // close: if(!is_numeric($imageWidth) && !is_numeric($imageHeight))
        } else {
            //Subimos la imagen con sus dimensiones originales (sin resize)
            // if directory doesn't exist, it is created.
            if (!file_exists($directory)) {
                mkdir($directory, 0777, true);
            }
            move_uploaded_file($FILE, $directory . $fileName_final);
            // Moving Uploaded imagen
        }
        //////////// THUMBNAIL  /////////////////////////////////////////////////////////
        // If thumbnail is required.
        if ($thumbWidth != NULL || $thumbHeight != NULL) {
            if (is_numeric($thumbWidth) || is_numeric($thumbHeight)) {
                // resample thumbnail
                $thumb = new SimpleImage();
                $thumb->load($FILE);
                if (is_numeric($thumbWidth) && is_numeric($thumbHeight)) {
                    if ($thumb->getWidth() > $thumbWidth || $thumb->getHeight() > $thumbHeight) {
                        if ($thumb->getWidth() > $thumbWidth) {
                            $thumb->resizeToWidth($thumbWidth);
                        }
                        if ($thumb->getHeight() > $thumbHeight) {
                            $thumb->resizeToHeight($thumbHeight);
                        }
                    }
                } else {
                    if (is_numeric($thumbWidth) && !is_numeric($thumbHeight)) {
                        if ($thumb->getWidth() > $thumbWidth) {
                            $thumb->resizeToWidth($thumbWidth);
                        }
                    } else {
                        if (!is_numeric($thumbWidth) && is_numeric($thumbHeight)) {
                            if ($thumb->getHeight() > $thumbHeight) {
                                $thumb->resizeToHeight($thumbHeight);
                            }
                        }
                    }
                }
                $thumbnailsDirectory = $directory . "thumbs/";
                // if directory doesn't exist, it is created.
                if (!file_exists($thumbnailsDirectory)) {
                    mkdir($thumbnailsDirectory, 0777, true);
                }
                // save thumb into thumbnails directory.
                $thumb->save($thumbnailsDirectory . $fileName_final);
            }
            // close: if(!is_numeric($thumbWidth) && !is_numeric($thumbHeight))
        }
        // close: if($thumbWidth != NULL || $thumbHeight != NULL)
        //////////// THUMBNAIL ENDS HERE /////////////////////////////////////////////////
        // delete temporary uploaded file.
        unlink($FILE);
        return $fileName_final;
    } else {
        // close: if($FILE != NULL)
        return NULL;
    }
}
function xuly_image($img, $uploaddir, $url_img, $url_img_thumb)
{
    $file = $uploaddir . $img;
    $size_info = getimagesize($file);
    if (is_array($size_info)) {
        include_once '../php/SimpleImage.php';
        $image = new SimpleImage();
        $url_img_thumb = '../' . $url_img_thumb;
        $url_img = '../' . $url_img;
        $image->load($file);
        $image->resizeToWidth(250);
        $image->save($url_img_thumb . $img);
        $image->load($file);
        $width = $size_info[0];
        $height = $size_info[1];
        if ($width >= $height && $width > 800) {
            $image->resizeToWidth(800);
        } elseif ($width >= $height && $width <= 800) {
            $image->resizeToWidth($width);
        } elseif ($width <= $height && $height > 500) {
            $image->resizeToHeight(500);
        } elseif ($width <= $height && $height <= 500) {
            $image->resizeToHeight($height);
        } else {
            return false;
        }
        $image->save($url_img . $img);
        unlink($file);
        return true;
    } else {
        return false;
    }
}
Beispiel #27
0
function resizeImagesInFolder($folder)
{
    //Time Limit vergrössern, da für viele Bilder viel Zeit in Anspruch genommen wird.
    set_time_limit(120);
    include 'includes/simpleImage.php';
    $image = new SimpleImage();
    if ($handle = opendir($folder)) {
        while (false !== ($file = readdir($handle))) {
            if ($file != "." && $file != "..") {
                $bild_location = $folder . "/" . $file;
                $info = getimagesize($bild_location);
                $width = $info[0];
                $height = $info[1];
                echo "<b>" . $bild_location . "</b><br>";
                echo 'Old width:' . $width . '<br>height:' . $height . "<br>";
                if ($height > 700) {
                    $image->load($bild_location);
                    $image->resizeToHeight(700);
                    $image->save($bild_location);
                }
                if ($width > 1200) {
                    $image->load($bild_location);
                    $image->resizeToWidth(1200);
                    $image->save($bild_location);
                }
                $info = getimagesize($bild_location);
                $width = $info[0];
                $height = $info[1];
                echo 'New width:' . $width . '<br>height:' . $height . "<br><br><br>";
            }
        }
    }
    return true;
}
Beispiel #28
0
 protected function _createThumbnail($file, $x, $y)
 {
     require_once NOLOTIRO_PATH . '/library/SimpleImage.php';
     $file_ext = substr(strrchr($file, '.'), 1);
     $fileuniquename = md5(uniqid(mktime())) . '.' . $file_ext;
     $image = new SimpleImage();
     $image->load('/tmp/' . $file);
     //save original to right place
     $widthmax = 900;
     $heightmax = 1000;
     $image->resizeToHeightMax($heightmax);
     $image->resizeToWidthMax($widthmax);
     $image->save(NOLOTIRO_PATH . '/www/images/uploads/ads/original/' . $fileuniquename);
     //save thumb
     $image->resizeToHeight($y);
     $image->resizeToWidth($x);
     $image->save(NOLOTIRO_PATH . '/www/images/uploads/ads/100/' . $fileuniquename);
     return $fileuniquename;
 }
Beispiel #29
0
 function check_size_and_rotation($pathname)
 {
     require_once mnminclude . "simpleimage.php";
     $original = $pathname;
     $tmp = "{$pathname}.tmp";
     $max_size = 2048;
     $image = new SimpleImage();
     if ($image->rotate_exif($pathname)) {
         if ($image->save($tmp)) {
             $pathname = $tmp;
             clearstatcache();
         }
     }
     if (filesize($pathname) > 1024 * 1024) {
         // Bigger than 1 MB
         if ($image->load($pathname) && ($image->getWidth() > $max_size || $image->getHeight() > $max_size)) {
             if ($image->getWidth() > $image->getHeight) {
                 $image->resizeToWidth($max_size);
             } else {
                 $image->resizeToHeight($max_size);
             }
             if ($image->save($tmp)) {
                 $pathname = $tmp;
                 clearstatcache();
             }
         }
     }
     if ($pathname != $original && file_exists($pathname)) {
         if (!@rename($pathname, $original)) {
             syslog(LOG_INFO, "Error renaming file {$pathname} -> {$original}");
             @unlink($pathname);
         }
     }
     $this->size = filesize($original);
     @chmod($original, 0777);
     return true;
 }
Beispiel #30
0
                foreach ($trash as $tr => $ash) {
                    if ($ash !== '.' && $ash !== '..') {
                        unlink("../base/img/{$imgdir}/res/{$ash}");
                    } else {
                    }
                }
                rmdir("../base/img/{$imgdir}/res");
                print "директория ../base/img/{$imgdir}/res и все ее содержимое успешно удалены</br>";
                $imgs = scandir("../base/img/{$imgdir}");
                mkdir("../base/img/{$imgdir}/res");
                print "директория ../base/img/{$imgdir}/res успешно создана</br>";
                foreach ($imgs as $noi => $image) {
                    if ($image !== '.' && $image !== '..' && $image !== 'Thumbs.db' && $image !== 'res') {
                        $simage = new SimpleImage();
                        $simage->load("../base/img/{$imgdir}/{$image}");
                        $simage->resizeToHeight($ih);
                        $simage->save("../base/img/{$imgdir}/res/{$image}");
                    } else {
                    }
                }
                print "--- миниатюры для ../base/img/{$imgdir} успешно созданы</br>";
            } elseif (is_dir("../base/img/{$imgdir}/res") && $select == 'skip') {
                print "!директория ../base/img/{$imgdir}/res уже существует!</br>";
            } else {
            }
        } else {
        }
    }
} else {
}
//-------------------------------------------------------------------------------------------------------------