when seeding I only need to ensure that a photo exists for the fragment
 so will return existing photo if it can be found
14566
def seed_fragment_photo(block_label, photo_file)
      # content_key = self.slug + "_" + page_part_key
      # get in content model associated with page and fragment
      # join_model = page_contents.find_or_create_by(page_part_key: page_part_key)
      # page_fragment_content = join_model.create_content(page_part_key: page_part_key)
      # join_model.save!
      # page_fragment_content = contents.find_or_create_by(page_part_key: page_part_key)

      page_fragment_content = find_or_create_content

      photo = page_fragment_content.content_photos.find_by_block_key(block_label)

      if photo.present?
        return photo
      else
        photo = page_fragment_content.content_photos.create(block_key: block_label)
      end

      if ENV["RAILS_ENV"] == "test"
        # don't create photos for tests
        return nil
      end
      begin
        # if photo_file.is_a?(String)
        # photo.image = photo_file
        photo.image = Pwb::Engine.root.join(photo_file).open
        photo.save!
        print "#{slug}--#{page_part_key} image created: #{photo.optimized_image_url}\n"
        # reload the record to ensure that url is available
        photo.reload
        print "#{slug}--#{page_part_key} image created: #{photo.optimized_image_url}(after reload..)"
      rescue Exception => e
        # log exception to console
        print e
      end
      photo
    end
748190
private void ensureDefaultOccurElements(IChemObjectBuilder builder) {
        if (mfRange == null) {
            String[] elements = new String[]{"C", "H", "O", "N", "Si", "P", "S", "F", "Cl", "Br", "I", "Sn", "B", "Pb",
                    "Tl", "Ba", "In", "Pd", "Pt", "Os", "Ag", "Zr", "Se", "Zn", "Cu", "Ni", "Co", "Fe", "Cr", "Ti",
                    "Ca", "K", "Al", "Mg", "Na", "Ce", "Hg", "Au", "Ir", "Re", "W", "Ta", "Hf", "Lu", "Yb", "Tm", "Er",
                    "Ho", "Dy", "Tb", "Gd", "Eu", "Sm", "Pm", "Nd", "Pr", "La", "Cs", "Xe", "Te", "Sb", "Cd", "Rh",
                    "Ru", "Tc", "Mo", "Nb", "Y", "Sr", "Rb", "Kr", "As", "Ge", "Ga", "Mn", "V", "Sc", "Ar", "Ne", "Be",
                    "Li", "Tl", "Pb", "Bi", "Po", "At", "Rn", "Fr", "Ra", "Ac", "Th", "Pa", "U", "Np", "Pu"};

            mfRange = new MolecularFormulaRange();
            for (int i = 0; i < elements.length; i++)
                mfRange.addIsotope(builder.newInstance(IIsotope.class, elements[i]), 0, 50);
        }
    }
1043310
public static void checkReshapeB(ImageMultiBand<?> imgA, ImageMultiBand<?> imgB) {
		if( imgA == imgB )
			throw new IllegalArgumentException("Image's can't be the same instance");
		imgB.reshape(imgA.width,imgA.height,imgA.getNumBands());
	}
1371079
def image_exists(self, id=None, tag=None):
        
        exists = False
        if id and self.image_by_id(id):
            exists = True
        elif tag and self.image_by_tag(tag):
            exists = True

        return exists
469080
def fetch_and_create_image(self, url, image_title):
        '''
        
        '''

        context = {
            "file_url": url,
            "foreign_title": image_title,
        }
        try:
            image_file = requests.get(url)
            local_image = Image(
                title=image_title,
                file=ImageFile(
                    BytesIO(image_file.content),
                    name=image_title
                )
            )
            local_image.save()
            return (local_image, context)
        except Exception as e:
            context.update({
                "exception": e,
            })
            raise ImageCreationFailed(context, None)
863328
def create_fragment_photo(page_part_key, block_label, photo_file)
      # content_key = self.slug + "_" + page_part_key
      # get content model associated with page and fragment
      page_fragment_content = contents.find_or_create_by(page_part_key: page_part_key)

      if ENV["RAILS_ENV"] == "test"
        # don't create photos for tests
        return nil
      end
      begin
        photo = page_fragment_content.content_photos.create(block_key: block_label)
        photo.image = photo_file
        # photo.image = Pwb::Engine.root.join(photo_file).open
        photo.save!
      rescue Exception => e
        # log exception to console
        print e
        # if photo
        #   photo.destroy!
        # end
      end
      photo
    end
138445
public static void checkReshape(ImageBase<?> imgA, ImageBase<?> imgB) {
		if( imgA == imgB )
			throw new IllegalArgumentException("Image's can't be the same instance");
		imgB.reshape(imgA.width,imgA.height);
	}
56689
function (callback) {
        if (!self._image) {
          var paths = (process.env.PATH || '').split(delimiter);
          if (!_.find(paths, function(p) {
            if (fs.existsSync(p + '/imagecrunch')) {
              self._image = require('./lib/image/imagecrunch.js')();
              return true;
            }
            // Allow for Windows and Unix filenames for identify. Silly oversight
            // after getting delimiter right (:
            if (fs.existsSync(p + '/identify') || fs.existsSync(p + '/identify.exe')) {
              self._image = require('./lib/image/imagemagick.js')();
              return true;
            }
          })) {
            // Fall back to jimp, no need for an error
            self._image = require('./lib/image/jimp.js')();
          }
        }
        return callback(null);
      }
1362424
def _match_auto(self, screen, search_img, threshold):
        
        # 1. try template first
        ret = ac.find_template(screen, search_img)
        if ret and ret['confidence'] > threshold:
            return FindPoint(ret['result'], ret['confidence'], consts.IMAGE_MATCH_METHOD_TMPL, matched=True)

        # 2. try sift
        ret = ac.find_sift(screen, search_img, min_match_count=10)
        if ret is None:
            return None

        matches, total = ret['confidence']
        if 1.0*matches/total > 0.5: # FIXME(ssx): sift just write here
            return FindPoint(ret['result'], ret['confidence'], consts.IMAGE_MATCH_METHOD_SIFT, matched=True)
        return None
722601
public void setPhoto(Photo photo) {
        PhotoType type = photo.getType();
        if (postType != null && !postType.equals(type)) {
            throw new IllegalArgumentException("Photos must all be the same type (source or data)");
        } else if (postType == PhotoType.SOURCE && pendingPhotos.size() > 0) {
            throw new IllegalArgumentException("Only one source URL can be provided");
        }
        pendingPhotos = new ArrayList<Photo>();
        pendingPhotos.add(photo);
        this.postType = type;
    }
329963
def haveSnapshots(self):
		""""""
		return os.path.islink(self.latestLink) and os.path.isdir(self.latestLink)
831626
private static ReuseResult loadBitmapReuseExact(ImageSource source, Bitmap dest) throws ImageLoadException {
        ImageMetadata metadata = source.getImageMetadata();
        boolean tryReuse = false;
        if (dest.isMutable()
                && dest.getWidth() == metadata.getW()
                && dest.getHeight() == metadata.getH()) {
            if (Build.VERSION.SDK_INT >= 19) {
                tryReuse = true;
            } else if (Build.VERSION.SDK_INT >= 11) {
                if (metadata.getFormat() == ImageFormat.JPEG || metadata.getFormat() == ImageFormat.PNG) {
                    tryReuse = true;
                }
            }
        }

        if (tryReuse) {
            return source.loadBitmap(dest);
        } else {
            return new ReuseResult(loadBitmap(source), false);
        }
    }
1234289
private static Observable<Bitmap> getThumbnailFromUriWithSize(final Context context,
      final Uri data, final int requiredWidth, final int requiredHeight) {
    return getThumbnailFromUriWithSizeAndKind(context, data, requiredWidth, requiredHeight,
        MediaStore.Images.Thumbnails.MINI_KIND);
  }
1213592
@SuppressWarnings("checkstyle:all")
	private ImageDescriptor getPackageFragmentIcon(IPackageFragment fragment) {
		boolean containsJavaElements = false;
		try {
			containsJavaElements = fragment.hasChildren();
		} catch (JavaModelException e) {
			// assuming no children;
		}
		try {
			if (!containsJavaElements) {
				final Object[] resources = fragment.getNonJavaResources();
				if (resources.length > 0) {
					for (final Object child : resources) {
						if (isSarlResource(child)) {
							return JavaPluginImages.DESC_OBJS_PACKAGE;
						}
					}
					return JavaPluginImages.DESC_OBJS_EMPTY_PACKAGE_RESOURCES;
				}
			}
		} catch (JavaModelException exception) {
			//
		}
		if (!containsJavaElements) {
			return JavaPluginImages.DESC_OBJS_EMPTY_PACKAGE;
		}
		return JavaPluginImages.DESC_OBJS_PACKAGE;
	}
325520
def make_file_exist(self):
        """"""
        self.parent.make_directory_exist()
        self.parent.touch_file(self.name)
        return self
1017644
function( isUndo )
		{
			var snapshots = this.snapshots,
				currentImage = this.currentImage,
				image, i;

			if ( currentImage )
			{
				if ( isUndo )
				{
					for ( i = this.index - 1 ; i >= 0 ; i-- )
					{
						image = snapshots[ i ];
						if ( !currentImage.equals( image, true ) )
						{
							image.index = i;
							return image;
						}
					}
				}
				else
				{
					for ( i = this.index + 1 ; i < snapshots.length ; i++ )
					{
						image = snapshots[ i ];
						if ( !currentImage.equals( image, true ) )
						{
							image.index = i;
							return image;
						}
					}
				}
			}

			return null;
		}
1153420
public function exists()
    {
        try {
            $result = $this->getSoapClient()->ImageExists(array(
                'filename' => basename($this->filename) ,
            ));

            return ( boolean ) $result->ImageExistsResult;
        } catch ( SoapException $e ) {
            throw new StatusException('Error while verifying existence of the image' , $e);
        }
    }