public function saveImages($filearray, $controllername, $uid)
 {
     $time = time();
     $saveFilename = '';
     foreach ($filearray as $file) {
         $nameArray = explode('.', $file->getName());
         $filetype = $nameArray[count($nameArray) - 1];
         $tmpFile = '../app/cache/tmp/' . $time . '_' . $file->getName();
         $file->moveTo($tmpFile);
         $thumbFilenameS = '../public/media/' . $controllername . '_' . $uid . '_S.' . $filetype;
         $thumbFilenameL = '../public/media/' . $controllername . '_' . $uid . '_L.' . $filetype;
         $saveFilename = 'public/media/' . $controllername . '_' . $uid . '_L.' . $filetype;
         $imageS = new GDAdapter($tmpFile);
         $imageS->resize(300, 1000);
         $imageS->save($thumbFilenameS);
         $imageL = new GDAdapter($tmpFile);
         $imageL->resize(600, 1000);
         $imageL->save($thumbFilenameL);
         unlink($tmpFile);
     }
     return $saveFilename;
 }
示例#2
0
 public function zipAction($product_id = null, $flip = null)
 {
     $this->view->disable();
     // Create tmp directory if it doesn't exist
     if (!file_exists(ROOT . "/public/tmp")) {
         mkdir(ROOT . "/public/tmp", 0777);
     }
     $random = rand(111111, 999999);
     $zip_name = "tmp/{$product_id}_{$random}.zip";
     $zip = new ZipArchive();
     $zip->open($zip_name, ZIPARCHIVE::CREATE);
     //        $zip->open($zip_name, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE);
     $photos = PProdPhoto::find(["product_id = {$product_id}", 'order' => 'ordered ASC']);
     $num = 1;
     $list_of_photos = [];
     foreach ($photos as $photo) {
         $img_name = "{$product_id}_{$num}";
         $jpg_name = "tmp/{$img_name}.{$photo->ext}";
         $img_dest = ROOT . "/public/tmp/{$random}_{$random}.{$photo->ext}";
         // Copy img to disk
         copy("http://madeheart.com/media/productphoto/{$photo->folder}{$photo->uri}.{$photo->ext}", $img_dest);
         $image_flip = new GD($img_dest);
         if ($flip == 'mirror') {
             $image_flip->flip(2);
         }
         $image_flip->save($jpg_name);
         // Delete temp file
         unlink($img_dest);
         $zip->addFile($jpg_name, basename($jpg_name));
         $list_of_photos[] = $jpg_name;
         $num++;
     }
     $zip->close();
     // Delete all jpg files in tmp folder
     foreach ($list_of_photos as $p) {
         unlink(ROOT . "/public/{$p}");
     }
     //        array_map('unlink', glob(ROOT."/public/tmp/*.jpg"));
     header('Content-Type: application/zip');
     header('Content-Length: ' . filesize($zip_name));
     header('Content-Disposition: attachment; filename="' . $product_id . '_' . $random . '.zip"');
     readfile($zip_name);
     // Delete zip file
     unlink(ROOT . "/public/{$zip_name}");
 }
示例#3
0
 /**
  * Resize of image uploaded
  * @param  string  $source
  * @param  string  $dest
  * @param  integer $new_width
  * @param  integer $new_height
  * @return   boolean
  */
 private function resizeImage($source, $dest, $new_width, $new_height)
 {
     $image = new GD($source);
     $source_height = $image->getHeight();
     $source_width = $image->getWidth();
     $source_aspect_ratio = $source_width / $source_height;
     $desired_aspect_ratio = $new_width / $new_height;
     if ($source_aspect_ratio > $desired_aspect_ratio) {
         $temp_height = $new_height;
         $temp_width = (int) ($new_height * $source_aspect_ratio);
     } else {
         $temp_width = $new_width;
         $temp_height = (int) ($new_width / $source_aspect_ratio);
     }
     $x0 = ($temp_width - $new_width) / 2;
     $y0 = ($temp_height - $new_height) / 2;
     $image->resize($temp_width, $temp_height)->crop($new_width, $new_height, $x0, $y0);
     return $image->save($dest);
 }