示例#1
0
         //START >> tinify images
         $tmp_path = str_replace(getcwd() . '/', "", $row_obj->path);
         //GET SERVER PATH
         $save_path = str_replace($row_obj->filename, "", $tmp_path);
         //OVERRIDE CURRENT LOCATION
         $flag = tinifyImage($row_obj->path, $save_path);
         if ($flag === false) {
             if ($error_message == "N") {
                 $error_message = "Y - Compression failed";
             } else {
                 $error_message .= " - Compression failed";
             }
         }
         //END << tinify image
         //UPDATE DB
         updateTableResizes($row_obj->id, $row_obj->round, $row_obj->filename, $row_obj->path, 1, $error_message, time(), $row_obj->timeAdded);
         if ($counter == 3) {
             break;
         }
     }
 }
 $totalAll7 = countAllByRoundNumber($round);
 $total_success = countSuccessfulByRoundNumber($round);
 $total_failed = countFailedByRoundNumber($round);
 $badFiles = array();
 if (!empty($total_failed)) {
     $failed_results = selectFailedByRoundNumber($round);
     foreach ($failed_results as $row) {
         $result_array = array('id' => intval($row['id']), 'filename' => $row['file_name'], 'error' => $row['error']);
         $badFiles[] = $result_array;
     }
示例#2
0
function addImage($object, $destinationPath, $picture, $filename, $newfileName, $extension, $mimeType, $fieldName)
{
    list($source_image_width, $source_image_height, $source_image_type) = getimagesize($destinationPath . $picture);
    $imageObjectInfo = array();
    $imageObjectInfo['width'] = $source_image_width;
    $imageObjectInfo['height'] = $source_image_height;
    $imageObjectInfo['fileName'] = $filename;
    $imageObjectInfo['filePath'] = $newfileName . '.' . $extension;
    $imageObjectInfo['sizes'] = array();
    $x = autoCrop($destinationPath, $picture, $fieldName);
    if ($x !== false) {
        $round = (int) \App\ResizesTinypng::max('round') + 1;
        insertIntoTableResizes($round, getTheImageSize($picture, $fieldName), $destinationPath . 'cropped/' . getTheImageSize($picture, $fieldName), 0, 'N', 0, false);
        $results_table = selectByRoundNumber($round);
        if (!empty($results_table)) {
            foreach ($results_table as $res_row) {
                $result_array = array('id' => intval($res_row['id']), 'round' => intval($res_row['round']), 'filename' => $res_row['file_name'], 'path' => $res_row['path'], 'runTiny' => intval($res_row['run_tiny']), 'error' => $res_row['error'], 'timeTiny' => intval($res_row['time_tiny']), 'timeAdded' => intval($res_row['created_at']));
                $row_obj = array_to_object($result_array);
                $error_message = "N";
                //START >> tinify images
                $tmp_path = str_replace(getcwd() . '/', "", $row_obj->path);
                //GET SERVER PATH
                $save_path = str_replace($row_obj->filename, "", $tmp_path);
                //OVERRIDE CURRENT LOCATION
                $flag = tinifyImage($row_obj->path, $save_path);
                if ($flag === false) {
                    if ($error_message == "N") {
                        $error_message = "Y - Compression failed";
                    } else {
                        $error_message .= " - Compression failed";
                    }
                }
                //END << tinify image
                //UPDATE DB
                updateTableResizes($row_obj->id, $row_obj->round, $row_obj->filename, $row_obj->path, 1, $error_message, time(), $row_obj->timeAdded);
            }
        }
    }
    /*
        if ($source_image_width > 1920) {//} || $source_image_height > 1080) {
            Thumbnail::generate_image_thumbnail($destinationPath . $picture, $destinationPath . $newfileName . '-resized.'. $extension, 1920, 1080);
        list($siw, $sih, $sit) = getimagesize($destinationPath . $newfileName . '-resized.'. $extension);
        rename( $destinationPath . $newfileName . '-resized.'. $extension,
                $destinationPath . $newfileName . '-'. $siw . 'x'. $sih .  '.'. $extension);
        $imageInfo = array();
        $imageInfo['fileName'] = $destinationPath . $newfileName . '-'. $siw . 'x'. $sih .  '.'. $extension;
            $imageInfo['width'] = $siw;
            $imageInfo['height'] = $sih;
            $imageInfo['mimeType'] = $mimeType;
        $imageObjectInfo['sizes']['large'] = $imageInfo;
        }
    if ($source_image_width > 1024) { // || $source_image_height > 768) {
            Thumbnail::generate_image_thumbnail($destinationPath . $picture, $destinationPath . $newfileName . '-resized.'. $extension, 1024, 768);
        list($siw, $sih, $sit) = getimagesize($destinationPath . $newfileName . '-resized.'. $extension);
        rename( $destinationPath . $newfileName . '-resized.'. $extension,
                $destinationPath . $newfileName . '-'. $siw . 'x'. $sih .  '.'. $extension);
        $imageInfo = array();
        $imageInfo['fileName'] = $newfileName . '-'. $siw . 'x'. $sih .  '.'. $extension;
            $imageInfo['width'] = $siw;
            $imageInfo['height'] = $sih;
            $imageInfo['mimeType'] = $mimeType;
        $imageObjectInfo['sizes']['medium'] = $imageInfo;
        }
    if ($source_image_width > 350) {//|| $source_image_height > 350) {
            Thumbnail::generate_image_thumbnail($destinationPath . $picture, $destinationPath . $newfileName . '-resized.'. $extension, 350, 350);
        list($siw, $sih, $sit) = getimagesize($destinationPath . $newfileName . '-resized.'. $extension);
        rename( $destinationPath . $newfileName . '-resized.'. $extension,
                $destinationPath . $newfileName . '-'. $siw . 'x'. $sih .  '.'. $extension);
        $imageInfo = array();
        $imageInfo['fileName'] = $newfileName . '-'. $siw . 'x'. $sih .  '.'. $extension;
            $imageInfo['width'] = $siw;
            $imageInfo['height'] = $sih;
            $imageInfo['mimeType'] = $mimeType;
        $imageObjectInfo['sizes']['small'] = $imageInfo;
        }
    if ($source_image_width > 300) {//|| $source_image_height > 350) {
            Thumbnail::generate_image_thumbnail($destinationPath . $picture, $destinationPath . $newfileName . '-resized.'. $extension, 300, 300);
        list($siw, $sih, $sit) = getimagesize($destinationPath . $newfileName . '-resized.'. $extension);
        rename( $destinationPath . $newfileName . '-resized.'. $extension,
                $destinationPath . $newfileName . '-'. $siw . 'x'. $sih .  '.'. $extension);
        $imageInfo = array();
        $imageInfo['fileName'] = $newfileName . '-'. $siw . 'x'. $sih .  '.'. $extension;
            $imageInfo['width'] = $siw;
            $imageInfo['height'] = $sih;
            $imageInfo['mimeType'] = $mimeType;
        $imageObjectInfo['sizes']['thumbnail'] = $imageInfo;
        }
    */
    // Save image object
    if ($imageObjectId = ObjectMeta::getValue($object->id, $fieldName)) {
        $imageObject = Object::find($imageObjectId);
    }
    if (empty($imageObject)) {
        $imageObject = new Object();
    }
    $imageObject->author_id = Auth::user()->id;
    $imageObject->type = 'image';
    $imageObject->name = $newfileName . '.' . $extension;
    $imageObject->title = $filename;
    $imageObject->status = 'inherit';
    $imageObject->guid = $newfileName;
    $imageObject->save();
    ObjectMeta::setValue($imageObject->id, '_file_path', $newfileName . '.' . $extension);
    ObjectMeta::setValue($imageObject->id, '_image_info', serialize($imageObjectInfo));
    ObjectMeta::setValue($object->id, $fieldName, $imageObject->id);
    return $imageObject;
}