class ImageMixin(models.Model): image_file = ImageField( _("image"), upload_to=UPLOAD_TO, width_field="image_width", height_field="image_height", ppoi_field="image_ppoi", blank=True, max_length=1000, ) image_width = models.PositiveIntegerField(_("image width"), blank=True, null=True, editable=False) image_height = models.PositiveIntegerField(_("image height"), blank=True, null=True, editable=False) image_ppoi = PPOIField(_("primary point of interest")) image_alt_text = models.CharField(_("alternative text"), max_length=1000, blank=True) class Meta: abstract = True verbose_name = _("image") verbose_name_plural = _("images") def accept_file(self, value): if upload_is_image(value): self.image_file = value return True
class Image(models.Model): """ Image plugin """ image = ImageField( _('image'), upload_to='images/%Y/%m', width_field='width', height_field='height', ppoi_field='ppoi', # NOTE! You probably want to use auto_add_fields=True in your own # models and not worry about setting the *_field vars above. ) width = models.PositiveIntegerField( _('image width'), blank=True, null=True, editable=False, ) height = models.PositiveIntegerField( _('image height'), blank=True, null=True, editable=False, ) ppoi = PPOIField(_('primary point of interest')) class Meta: abstract = True verbose_name = _('image') verbose_name_plural = _('images') def __str__(self): return self.image.name
class AbstractModel(models.Model): image = ImageField( _("image"), upload_to="images", width_field="width", height_field="height", ppoi_field="ppoi", formats={ "thumb": ["default", ("crop", (300, 300))], "desktop": ["default", ("thumbnail", (300, 225))], }, # Should have no effect, but not hurt either: auto_add_fields=True, ) width = models.PositiveIntegerField(_("image width"), blank=True, null=True, editable=False) height = models.PositiveIntegerField(_("image height"), blank=True, null=True, editable=False) ppoi = PPOIField(_("primary point of interest")) class Meta: abstract = True
class CVDocumentPhoto(models.Model): id_name = models.CharField( max_length=255, verbose_name=gettext_lazy("Photo identification name")) source = ImageField(verbose_name=gettext_lazy("Image"), height_field='height', width_field='width', ppoi_field='ppoi', upload_to='cv-photo/', formats={'full': [ 'default', ]}) width = models.PositiveIntegerField( verbose_name=gettext_lazy("Image width")) height = models.PositiveIntegerField( verbose_name=gettext_lazy("Image height")) ppoi = PPOIField('Image PPOI') def __str__(self): return self.id_name class Meta: verbose_name = gettext_lazy("Photo") verbose_name_plural = gettext_lazy("Photos") db_table = 'app_owner_cv_doc_photo'
class ProjectGalleryImage(models.Model): order = models.PositiveIntegerField(default=0) gallery = models.ForeignKey( 'ProjectGallery', on_delete=models.CASCADE, ) image = ImageField(verbose_name=gettext_lazy("Image"), height_field='height', width_field='width', ppoi_field='ppoi', upload_to='project_gallery/', formats={ 'thumb': ['default', ('thumbnail', (250, 180))], 'thumb_webp': thumb_webp_processor_spec, 'full': [ 'default', ], 'full_webp': webp_processor_spec }) width = models.PositiveIntegerField( verbose_name=gettext_lazy("Image width")) height = models.PositiveIntegerField( verbose_name=gettext_lazy("Image height")) ppoi = PPOIField('Image PPOI') alt = models.CharField(max_length=255, default='image') def toJson(self): return { 'width': self.width, 'height': self.height, 'url': self.image.thumb } def __str__(self): return '' class Meta: verbose_name = gettext_lazy("Gallery Image") verbose_name_plural = gettext_lazy("Gallery Images") db_table = 'app_projects_project_gallery_image' ordering = ['order']
class Image(MediaBase): image_width = models.PositiveIntegerField(_("image width"), blank=True, null=True, editable=False) image_height = models.PositiveIntegerField(_("image height"), blank=True, null=True, editable=False) image_ppoi = PPOIField(_("primary point of interest")) # file = models.ImageField(_("Datei")) file = ImageField( _("image"), upload_to=UPLOAD_TO, width_field="image_width", height_field="image_height", ppoi_field="image_ppoi", blank=True, ) logo_image = ImageSpecField(source='file', processors=[ResizeToFit(150, 150)]) thumbnail = ImageSpecField( source='file', processors=[Adjust(contrast=1.2, sharpness=1.1), Thumbnail(100, 50)], format='JPEG', options={'quality': 90}) square_image = ImageSpecField(source='file', processors=[ResizeToFill(800, 800)], format='JPEG', options={'quality': 90}) small_article_image = ImageSpecField(source='file', processors=[ResizeToFit(400, 400)], format='JPEG', options={'quality': 90}) article_image = ImageSpecField(source='file', processors=[ResizeToFit(800, 800)], format='JPEG', options={'quality': 90}) gallery_image = ImageSpecField(source='file', processors=[ResizeToFit(1200, 1200)], format='JPEG', options={'quality': 90}) gallery_image_thumbnail = ImageSpecField( source='file', processors=[ Adjust(contrast=1.2, sharpness=1.1), # ResizeToFit(180, 120) ResizeToFit(220, 155) ], format='JPEG', options={'quality': 90}) lightbox_image = ImageSpecField(source='file', processors=[ResizeToFit(1600, 1600)], format='JPEG', options={'quality': 90}) highres_image = lightbox_image type = 'image' class Meta: verbose_name = _("Bild") verbose_name_plural = _("Bilder") ordering = ['imagegalleryrel__position'] # # Accessors to GIF images # FIXME ImageKit should leave alone GIF images in the first place # TODO Need more robust method to get image type def gif_gallery_image_thumbnail(self, image_spec_name='gallery_image_thumbnail'): # Return gif image URLs without converting. name, ext = posixpath.splitext(self.file.name) if ext == '.gif': return self.file else: return getattr(self, image_spec_name) def gif_lightbox_image(self): return self.gif_gallery_image_thumbnail( image_spec_name='lightbox_image')