Пример #1
0
        cloudinary.uploader.upload(req.files.file.path, function(result) { 

          if(req.body.width){

              width = req.body.width;

              img_big = cloudinary.url(result.public_id , { format: result.format, height: width, crop: 'scale'});

              img  = cloudinary.url(result.public_id , { format: result.format,                                                            
                                                          transformation:[{
                                                              height: width, crop: 'scale'
                                                          },{
                                                              width: 0, height: 0, x: 0, y: 0, crop: 'crop'
                                                          },
                                                          {
                                                            width:160, crop:'scale'
                                                          }]
                                                        });
          
          }else{

              img_big = cloudinary.url(result.public_id , { format: result.format, width: 800, crop: 'scale'});

              img = cloudinary.image(result.public_id , { format: result.format, width: 100, height: 100, crop: 'fill'});

          }

          res.json({public_id:result.public_id , image_th:img, image_big:img_big});

        });
Пример #2
0
    Student.findOne(req.param('id'), function foundUser(err, student) {
      if (err) return next(err);
      if (!student) return next();
      var cloudinary = require('cloudinary');
      var urlUp = 1;
   // console.log(cloudinary.url('sample.jpg'));
   if(!student.simageurl){
    urlUp = 0;
    student.simageurl = cloudinary.url(student.simage);
    //console.log(cloudinary.url(student.simage));
   }
   if(!student.image1url){
    urlUp = 0;
    student.image1url = cloudinary.url(student.image1);
    //console.log(cloudinary.url(student.simage));

   }
   if(!student.image2url){
    urlUp = 0;
    student.image2url = cloudinary.url(student.image2);
   }
   if(!student.image3url){
    urlUp = 0;
    student.image3url = cloudinary.url(student.image3);
   }
   if(!student.image4url){
    urlUp = 0;
    student.image4url = cloudinary.url(student.image2);
   }

if(urlUp==0){

  console.log("updating");
   var studObj = {
        simageurl: student.simageurl,
        image1url: student.image1url,
        image2url: student.image2url,
        image3url: student.image3url,
        image4url: student.image4url,
      }

    Student.update(req.param('id'), studObj, function studentUpdated(err) {
      if(err) return next(err);
    });
  }
  
   //student.image2 = cloudinary.url('sample.jpg');
    //student.image2 = cloudinary.url(student.image2);
   // student.update();
    Marks.findByAdminNo((student.adminNo), function foundMark(err, mark){
      if(err) return next(err);
      if (!mark) return next('marks doesn\'t exist.');
     res.view({
        student: student,
        marks: mark
      });
      
    });
  });
Пример #3
0
 it('url', () => {
   (cloudinary.url('foo'): string);
   (cloudinary.url('bar', {
     secure: true,
     transformation: [
       { width: 320, height: 256, crop: 'fit' },
       { width: 320, height: 256, crop: 'limit', quality: 60 },
     ],
   }): string);
 });
Пример #4
0
app.get('/user/:id', function(req,res){

    var user = req.getUser();

    var userId = parseInt(req.params.id)

    var imgId='user_'+userId;
    var imgThumb = cloudinary.url(imgId+'.jpg', {
        width: 260,
        height: 218,
        crop: 'fill',
        gravity: 'face',
        border: '3px_solid_rgb:000'
    });

//Before the .then is where you catch for NULL on USER. How?
    db.user.find({where: {id: req.params.id}}).then(function(userData){
        if (userData) {
            //could user userData.getPosts().then(function(postData){ everything else goes in here to dry it up})
        db.post.findAll({where: {userId: req.params.id}}).then(function(postData){
            db.neighborhood.findAll({order: 'name ASC'}).success(function(neighborhood){
                res.render('user/profile', {userData:userData, postData:postData, imgThumb:imgThumb, neighborhood:neighborhood, user:user});
            })
        })
    }
    else {
        res.render('user404')
    }
    }).catch(function(error) {
        res.send(404);
    });
    //the above only works if user enters a random string, not integers
})
Пример #5
0
				dpr.forEach(function(pr) {
					options.hash.width = w * pr;
					var url = cloudinary.url(imageName, options.hash);
					url = url.replace('http://', '//');

					dprSrcSet.push(url + ' ' + pr + 'x');
				});
 function(cb) {
   var projectUrl = req.body.url;
   var url = cloudinary.url( projectUrl,
     { type: "url2png", secure: true, crop: "fill", width: 300, height: 200, gravity: "north", sign_url: true });
   console.log("url ", url);
   cb(null, url);
 },
Пример #7
0
	var src = function (item, options) {

		if (!exists(item)) {
			return '';
		}

		options = (typeof options === 'object') ? options : {};

		if (!('fetch_format' in options) && keystone.get('cloudinary webp') !== false) {
			options.fetch_format = 'auto';
		}

		if (!('progressive' in options) && keystone.get('cloudinary progressive') !== false) {
			options.progressive = true;
		}

		if (!('secure' in options) && keystone.get('cloudinary secure')) {
			options.secure = true;
		}

		options.version = item.get(paths.version);

		return cloudinary.url(item.get(paths.public_id) + '.' + item.get(paths.format), options);

	};
Пример #8
0
	_helpers.cloudinaryUrl = function(context, options) {
		// if we dont pass in a context and just kwargs
		// then `this` refers to our default scope block and kwargs
		// are stored in context.hash
		if (!options && context.hasOwnProperty('hash')) {
			// strategy is to place context kwargs into options
			options = context;
			// bind our default inherited scope into context
			context = this;
		}

		// safe guard to ensure context is never null
		context = context === null ? undefined : context;

		if (context && context.public_id) {
			var imageName = context.public_id.concat('.', context.format);
			if (options.hash.format !== undefined) {
				imageName = imageName.substr(0, imageName.lastIndexOf('.'));
			}
			var url = cloudinary.url(imageName, options.hash);
			//if (window.location.protocol != "https:")
			url = url.replace('http://', '//');
			return url;
		} else {
			return null;
		}
	};
Пример #9
0
	var src = function (img, options) {
		if (keystone.get('cloudinary secure')) {
			options = options || {};
			options.secure = true;
		}
		return img.public_id ? cloudinary.url(img.public_id + '.' + img.format, options) : '';
	};
Пример #10
0
 var handleTheStreamResult = function (result) {
   savedContestant.pictures.push({
     serviceId: result.public_id,
     fileName: filename,
     url: cloudinary.url(result.public_id, CLOUDINARY_CONFIG.detail)
   });
   savedContestant.save();
 };
function buildCloudinaryUrl(imageServiceUrl, options) {
	if (!(imageServiceUrl instanceof ImageServiceUrl)) {
		throw new Error('Invalid argument, expected instance of ImageServiceUrl');
	}
	cloudinary.config({
		cloud_name: options.cloudinaryAccountName
	});
	return cloudinary.url(imageServiceUrl.source, buildCloudinaryTransforms(imageServiceUrl));
}
Пример #12
0
						var stream = cloudinary.uploader.upload(caminhoCompleto, function(result) {							
							fs.unlink(caminhoCompleto, function (erro) {
								if(erro){
									return cb(new app.models.erro('Erro ao fazer upload do arquivo', 'ERRO', erro));
								}
							});

							var urlCropada = cloudinary.url(result.public_id, obj);
							return cb(null, urlCropada);
						});							
Пример #13
0
	_helpers.styleizedImage2 = function(imageId) {
		return cloudinary.url(imageId, {
			transformation: [
				{ width: 500, height: 330, crop: "fill" },
				{ overlay: "purple_p12mc3", effect: "screen", opacity: 100, width: 500, height: 330 },
				{ overlay: "purple_p12mc3", effect: "multiply", opacity: 50, width: 500, height: 330 },
				{ overlay: "yellow_nltzn9", effect: "multiply", opacity: 15,  width: 500, height: 330 }

			]
		});
	}
Пример #14
0
	_helpers.styleizedImage = function(imageId, width, height) {
		if(!width) width = 500;
		if(!height) height = 330;
		
		return cloudinary.url(imageId, {
			transformation: [
				{ width: width, height: height, crop: "fill" },
				{ overlay: "purple_p12mc3", effect: "screen", opacity: 100, width: width, height: height },
				{ overlay: "yellow_nltzn9", effect: "multiply", opacity: 15,  width: width, height: height }

			]
		});
	}
Пример #15
0
function parsePhotos(obj) {
  var width = 225,
    height = 143,
    crop = 'fill',
    photos = [];

  if (obj) {
    Cloudinary.config({
      cloud_name: 'xandgo',
      api_key: process.env.CLOUDINARY_KEY,
      api_secret: process.env.CLOUDINARY_SECRET
    });

    if (obj.photos && obj.photos.length > 0) {
      for (var i = 0; i < obj.photos.length; i++) {
        photos.push(Cloudinary.url(obj.photos[i].public_id, {width: width, height: height, crop: crop}));
      }
    }

    if (obj.logo && photos.length === 0) {
      return Cloudinary.url(obj.logo.public_id, {
        width: width,
        height: height,
        crop: crop
      });
    }

    if (obj.location && photos.length === 0) {
      if (obj.location.geo) {
        return 'http://maps.googleapis.com/maps/api/staticmap?&markers=color:black%7C' + obj.location.geo[1] + ',' + obj.location.geo[0] + '&center=' + obj.location.geo[1] + ',' + obj.location.geo[0] + '&size=' + width + 'x' + height + '&zoom=15&sensor=false';
      }
    }
  }

  return photos;
}
Пример #16
0
app.get('/showPicture',function(req,res){

    // db.piece.find({where:{type:'shirts'}}).then(function(piece){
    //     var imgId = 'piece_'+piece.id;
    // })

    var imgId='user_1';
    var imgThumb1 = cloudinary.url(imgId+'.jpg', {
      width: 90,
      height: 98, 
      crop: 'fill',
      gravity: 'face',
      radius: 'max',
      effect: 'sepia' 
    });
    res.render('show',{myPicture:imgThumb1})
});
Пример #17
0
	_helpers.cloudinaryUrl = function(context, options) {
		// if we dont pass in a context and just kwargs
		// then `this` refers to our default scope block and kwargs
		// are stored in context.hash
		if (!options && context.hasOwnProperty('hash')) {
			// strategy is to place context kwargs into options
			options = context;
			// bind our default inherited scope into context
			context = this;
		}
		// safe guard to ensure context is never null
		context = context === null ? undefined : context;
		if ((context) && (context.public_id)) {
			var imageName = context.public_id.concat('.', context.format);
			return cloudinary.url(imageName, options.hash);
		} else {
			return null;
		}
	};
Пример #18
0
dust.helpers.picture = function (chunk, ctx, bodies, params) {
    params || (params = {});

    ctx = params.path
        ? ctx.get(params.path)
        : ctx.current();

    if (ctx.picture)
        ctx = ctx.picture;

    if (!ctx || !ctx.public_id)
        return chunk;

    params.format = params.format || ctx.format;

    return chunk.write(
        cloudinary.url(ctx.public_id, params)
    );
};
Пример #19
0
app.get('/user/myprofile', function(req,res){

    var user = req.getUser();

    if (user){
        var imgId='user_'+ user.id;
        var imgThumb = cloudinary.url(imgId+'.jpg', {
            width: 260,
            height: 218,
            crop: 'fill',
            gravity: 'face',
            border: '3px_solid_rgb:000'
        });

        db.user.find({where: {id: user.id}}).then(function(userData){
            db.post.findAll({where: {userId: user.id}}).then(function(postData){
                db.neighborhood.findAll({order: 'name ASC'}).success(function(neighborhood){
                    res.render('user/profile', {userData:userData, postData:postData, imgThumb:imgThumb, user:user, neighborhood:neighborhood});
                })
            })
        })
    };
})
Пример #20
0
app.get('/sendimage/:id', function(request, response, body)  {
  var p = request.params.id;

  console.log("PARAM " + p);
  var msg = "Sending image";

  var fimg = "http://res.cloudinary.com/lcbklf5b3/raw/upload/v1383329790/decodestr";
  var gimg = cloudinary.url(fimg);
  msg = msg + "<br><br>" + gimg;

  var http = require('http');

  var request = http.get(gimg, function(res) {
      var str = '';
      res.on('data', function(chunk) {
       str += chunk; 
      });   
      res.on('end', function() {
        //console.log('AT END '  + str);
        sendToCloud(str);
      });   
  });   
  response.send(msg);
});
Пример #21
0
 it('errors', () => {
   // $ExpectError
   cloudinary.config();
   // $ExpectError
   cloudinary.url();
 });
Пример #22
0
 html: function() {
     // TODO add facebook and twitter meta tags
     res.send('<html><body><img src="' + cloudinary.url(req.image.public_id, {format: 'jpg'}) + '"/></body></html>');
 },
Пример #23
0
exports.url = function(public_id, format, option) {
  return cloudinary.url(public_id + "." + format, option);
};
Пример #24
0
 cloudinary.uploader.upload(request.files.file.path, function (result) {
     var tmp = cloudinary.url(result.public_id+".jpg", {width: imageWidth, height: imageHeight, crop: "scale"});
     // TODO insert to db before sending response
     response.send(tmp);
 }, {public_id: request.files.file.name.replace(/\.(.*?)$/i, "")});
Пример #25
0
 .forEach(picture => picture.url = cloudinary.url(picture.serviceId, CLOUDINARY_CONFIG.thumbnail)));
Пример #26
0
module.exports = function loadPlugin (projectPath, Plugin) {
  const plugin = new Plugin(__dirname);

  plugin.cloudinary = cloudinary;

  // set plugin configs
  plugin.setConfigs({
    upload: {
      storages: {
        cloudinary: {
          isLocalStorage: false,
          getStorage(we) {
            if (!we.config.apiKeys.cloudinary) {
              console.log('configure your cloudinary api keys in: we.config.apiKeys.cloudinary');
              we.exit(function(){ process.exit(); });
            }

            cloudinary.config({
              cloud_name: we.config.apiKeys.cloudinary.cloud_name,
              api_key: we.config.apiKeys.cloudinary.api_key,
              api_secret: we.config.apiKeys.cloudinary.api_secret
            });

            return cloudinaryStorage({
              cloudinary: cloudinary,
              getDestination: this.getDestination,
              filename: this.filename
            });
          },
          /**
           * Send one file to user
           *
           * @param  {Object} file
           * @param  {Object} req
           * @param  {Object} res
           * @param  {String} style
           */
          sendFile(file, req, res, style) {
            if (!style) style = 'original';
            // send to cloudinary file
            res.redirect( ( file.urls[style] || file.urls.original) );
          },
          destroyFile(file, done) {
            cloudinary.uploader
            .destroy(file.extraData.public_id, (result)=> {

              if (result.result != 'ok') {
                plugin.we.log.error('error on delete image from cloudinary:', result);
              }

              return done();
            });
          },
          getUrlFromFile(format, file) {
            if (!file.extraData) file.extraData = {
              public_id: file.public_id
            };

            file.name = file.wejsName;
            file.size = file.bytes;
            file.extension = '.'+file.format;

            return file.secure_url;
          },
          getDestination(style) {
            if (!style) style = 'original';
            return 'wejs-uploads/'+style;
          },
          getPath(style, name) {
            return path.join(
              this.getDestination(style),
              name
            );
          },

          /**
           * Make unique file name
           *
           * @param  {Object} req
           * @param  {Object} file
           * @return {String}      new file name
           */
          filename() {
            return Date.now() + '_' + uuid.v1();
          },

          generateImageStyles(file, done) {
            const we = plugin.we,
              styles = we.config.upload.image.avaibleStyles;

            for (let i = 0; i < styles.length; i++) {
              this.resizeEach(styles[i], file, this);
            }

            done();
          },

          /**
           * Resize one image to fit image style size
           *
           * @param  {String}   imageStyle
           * @param  {Object}   file
           * @param  {Object}   uploader
           * @param  {Function} next         callback
           */
          resizeEach(imageStyle, file) {
            const style = plugin.we.config.upload.image.styles[imageStyle];

            file.urls[imageStyle] = cloudinary
            .url(file.extraData.public_id, {
              width: style.width,
              height: style.width,
              crop: 'fit'
            });
          }
        }
      }
    }
  });

  /**
   * Plugin fast loader
   *
   * Defined for faster project bootstrap
   *
   * @param  {Object}   we
   * @param  {Function} done callback
   */
  plugin.fastLoader = function fastLoader(we, done) {
    done();
  };

  return plugin;
};
Пример #27
0
	_helpers.cloudinaryImgSrcSet = function(context, options) {
		if (!options && context.hasOwnProperty('hash')) {
			// strategy is to place context kwargs into options
			options = context;
			// bind our default inherited scope into context
			context = this;
		}

		// safe guard to ensure context is never null
		context = context === null ? undefined : context;

		if (options.hash.widths !== undefined) {
			options.hash.widths = JSON.parse(options.hash.widths);
		} else {
			return;
		}
		if (options.hash.screenWidths !== undefined) {
			options.hash.screenWidths = JSON.parse(options.hash.screenWidths);
		} else {
			return;
		}
		if (options.hash.index !== undefined) {
			options.hash.index = Math.floor(options.hash.index);
		}

		if (context && context.public_id) {
			var imageName = context.public_id.concat('.', context.format);
			if (options.hash.format !== undefined) {
				imageName = imageName.substr(0, imageName.lastIndexOf('.'));
			}
			var imgs = [];

			var styles = [];
			if (options.hash.index && (options.hash.onlyShowFirst !== undefined && options.hash.onlyShowFirst)) {
				styles.push('display:none');
			}
			var srcset = '<picture>'; //[290,330,345,381,384,405,500,600,700,738,720,536,652,652]
			if (options.hash.style) {
				srcset = '<picture style="' + options.hash.style + '">';
			}
			var screenWidths = options.hash.screenWidths;
			options.hash.width = options.hash.widths[options.hash.widths.length - 1];
			var origUrl = cloudinary.url(imageName, options.hash);
			origUrl = origUrl.replace('http://', '//');
			//options.hash.width = options.hash.widths[0];
			options.hash.widths.forEach(function(w, i) {
				var dpr = [1, 2, 3];
				var dprSrcSet = [];
				dpr.forEach(function(pr) {
					options.hash.width = w * pr;
					var url = cloudinary.url(imageName, options.hash);
					url = url.replace('http://', '//');

					dprSrcSet.push(url + ' ' + pr + 'x');
				});
				var srcSet = 'srcset="' + dprSrcSet.join(', ') + '"';
				if (options.hash.dataSrc !== undefined && options.hash.dataSrc) {
					srcSet = 'data-' + srcSet;
				}
				var source = '<source media="(max-width:' + screenWidths[i] + 'px)" ' + srcSet + '>';

				imgs.push(source);
			});
			srcset += imgs.join('\n');
			var id = '';
			if (options.hash.id !== undefined) {
				id = options.hash.id;
			}

			if (id && options.hash.index !== undefined) {
				id += options.hash.index;
			}
			styles.push('width:100%');
			var style = "style='";
			styles.forEach(function(s) {
				style += s + ';';
			});
			style += "'";
			srcset += '<img class="' + options.hash.class + '" ' + style;
			if (id) {
				srcset += 'id="' + id + '" ';
			}
			if (options.hash.dataSrc !== undefined && options.hash.dataSrc) {
				srcset += 'data-';
			}
			srcset += 'src="' + origUrl + '"></picture>';

			return srcset;
		} else {
			return null;
		}
	};